home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / game / text / inform_lib66.lha / parserm.h < prev    next >
Text File  |  1997-08-24  |  161KB  |  4,609 lines

  1. ! ----------------------------------------------------------------------------
  2. !  PARSERM:  Core of parser.
  3. !
  4. !  Supplied for use with Inform 6                         Serial number 970818
  5. !                                                                  Release 6/6
  6. !  (c) Graham Nelson 1993, 1994, 1995, 1996, 1997
  7. !      but freely usable (see manuals)
  8. ! ----------------------------------------------------------------------------
  9. !  Inclusion of "linklpa"
  10. !                   (which defines properties and attributes)
  11. !  Global variables, constants and arrays
  12. !                1: outside of the parser
  13. !                2: used within the parser
  14. !  Inclusion of natural language definition file
  15. !                   (which creates a compass and direction-objects)
  16. !  Darkness and player objects
  17. !  Definition of grammar token numbering system used by Inform
  18. !
  19. !  The InformParser object
  20. !          keyboard reading
  21. !          level 0: outer shell, conversation, errors
  22. !                1: grammar lines
  23. !                2: tokens
  24. !                3: object lists
  25. !                4: scope and ambiguity resolving
  26. !                5: object comparisons
  27. !                6: word comparisons
  28. !                7: reading words and moving tables about
  29. !          pronoun management
  30. !
  31. !  The InformLibrary object
  32. !          main game loop
  33. !          action processing
  34. !          end of turn sequence
  35. !          scope looping, before/after sequence, sending messages out
  36. !          timers, daemons, time of day, score notification
  37. !          light and darkness
  38. !          changing player personality
  39. !          tracing code (only present if DEBUG is set)
  40. !
  41. !  Status line printing, menu display
  42. !  Printing object names with articles
  43. !  Miscellaneous utility routines
  44. !  Game banner, "version" verb, run-time errors
  45. ! ----------------------------------------------------------------------------
  46.  
  47. System_file;
  48. Constant NULL = $ffff;
  49.  
  50. IFDEF MODULE_MODE;
  51. Constant DEBUG;
  52. Constant Grammar__Version 2;
  53. Include "linklpa";
  54. ENDIF;
  55.  
  56. ! ============================================================================
  57. !   Global variables and their associated Constant and Array declarations
  58. ! ----------------------------------------------------------------------------
  59. Global location = InformLibrary;     ! Must be first global defined
  60. Global sline1;                       ! Must be second
  61. Global sline2;                       ! Must be third
  62.                                      ! (for status line display)
  63. ! ------------------------------------------------------------------------------
  64. !   Z-Machine and interpreter issues
  65. ! ------------------------------------------------------------------------------
  66. Global top_object;                   ! Largest valid number of any tree object
  67. Global standard_interpreter;         ! The version number of the Z-Machine
  68.                                      ! Standard which the interpreter claims
  69.                                      ! to support, in form (upper byte).(lower)
  70. Global undo_flag;                    ! Can the interpreter provide "undo"?
  71. Global just_undone;                  ! Can't have two successive UNDOs
  72. Global transcript_mode;              ! true when game scripting is on
  73. IFDEF DEBUG;
  74. Global xcommsdir;                    ! true if command recording is on
  75. ENDIF;
  76. ! ------------------------------------------------------------------------------
  77. !   Time and score
  78. ! (for linkage reasons, the task_* arrays are created not here but in verblib.h)
  79. ! ------------------------------------------------------------------------------
  80. Global turns = 1;                    ! Number of turns of play so far
  81. Global the_time = NULL;              ! Current time (in minutes since midnight)
  82. Global time_rate = 1;                ! How often time is updated
  83. Global time_step;                    ! By how much
  84.  
  85. Constant MAX_TIMERS  64;             ! Actually only 32 (it's counting in bytes)
  86. Array  the_timers  --> 32;
  87. Global active_timers;                ! Number of timers/daemons actives
  88.  
  89. Global score;                        ! The current score
  90. Global last_score;                   ! Score last turn (for testing for changes)
  91. Global notify_mode = true;           ! Score notification
  92. Global places_score;                 ! Contribution to score made by visiting
  93. Global things_score;                 ! Contribution made by acquisition
  94. ! ------------------------------------------------------------------------------
  95. !   The player
  96. ! ------------------------------------------------------------------------------
  97. Global player;                       ! Which object the human is playing through
  98. Global deadflag;                     ! Normally 0, or false; 1 for dead;
  99.                                      ! 2 for victorious, and higher numbers
  100.                                      ! represent exotic forms of death
  101. ! ------------------------------------------------------------------------------
  102. !   Light and room descriptions
  103. ! ------------------------------------------------------------------------------
  104. Global lightflag = true;             ! Is there currently light to see by?
  105. Global real_location;                ! When in darkness, location = thedark
  106.                                      ! and this holds the real location
  107. Global visibility_ceiling;           ! Highest object in tree visible from
  108.                                      ! the player's point of view (usually
  109.                                      ! the room, sometimes darkness, sometimes
  110.                                      ! a closed non-transparent container).
  111.  
  112. Global lookmode = 1;                 ! 1=standard, 2=verbose, 3=brief room descs
  113. Global print_player_flag;            ! If set, print something like "(as Fred)"
  114.                                      ! in room descriptions, to reveal whom
  115.                                      ! the human is playing through
  116. Global lastdesc;                     ! Value of location at time of most recent
  117.                                      ! room description printed out
  118. ! ------------------------------------------------------------------------------
  119. !   List writing  (style bits are defined as Constants in "verblibm.h")
  120. ! ------------------------------------------------------------------------------
  121. Global c_style;                      ! Current list-writer style
  122. Global lt_value;                     ! Common value of list_together
  123. Global listing_together;             ! Object number of one member of a group
  124.                                      ! being listed together
  125. Global listing_size;                 ! Size of such a group
  126. Global wlf_indent;                   ! Current level of indentation printed by
  127.                                      ! WriteListFrom routine
  128.  
  129. Global inventory_stage = 1;          ! 1 or 2 according to the context in which
  130.                                      ! "invent" routines of objects are called
  131. Global inventory_style;              ! List-writer style currently used while
  132.                                      ! printing inventories
  133. ! ------------------------------------------------------------------------------
  134. !   Menus and printing
  135. ! ------------------------------------------------------------------------------
  136. Global pretty_flag = true;           ! Use character graphics, or plain text?
  137. Global menu_nesting;                 ! Level of nesting (0 = root menu)
  138. Global menu_item;                    ! These are used in communicating
  139. Global item_width = 8;               ! with the menu-creating routines
  140. Global item_name = "---";
  141.  
  142. Global lm_n;                         ! Parameters used by LibraryMessages
  143. Global lm_o;                         ! mechanism
  144.  
  145. IFDEF DEBUG;
  146. Global debug_flag;                   ! Bitmap of flags for tracing actions,
  147.                                      ! calls to object routines, etc.
  148. Global x_scope_count;                ! Used in printing a list of everything
  149.                                      ! in scope
  150. ENDIF;
  151. ! ------------------------------------------------------------------------------
  152. !   Action processing
  153. ! ------------------------------------------------------------------------------
  154. Global action;                       ! Action currently being asked to perform
  155. Global inp1;                         ! 0 (nothing), 1 (number) or first noun
  156. Global inp2;                         ! 0 (nothing), 1 (number) or second noun
  157. Global noun;                         ! First noun or numerical value
  158. Global second;                       ! Second noun or numerical value
  159.  
  160. Global keep_silent;                  ! If true, attempt to perform the action
  161.                                      ! silently (e.g. for implicit takes,
  162.                                      ! implicit opening of unlocked doors)
  163.  
  164. Global reason_code;                  ! Reason for calling a "life" rule
  165.                                      ! (an action or fake such as ##Kiss)
  166.  
  167. Global receive_action;               ! Either ##PutOn or ##Insert, whichever
  168.                                      ! is action being tried when an object's
  169.                                      ! "before" rule is checking "Receive"
  170. ! ==============================================================================
  171. !   Parser variables: first, for communication to the parser
  172. ! ------------------------------------------------------------------------------
  173. Global parser_trace = 0;             ! Set this to 1 to make the parser trace
  174.                                      ! tokens and lines
  175. Global parser_action;                ! For the use of the parser when calling
  176. Global parser_one;                   ! user-supplied routines
  177. Global parser_two;                   !
  178. Array  inputobjs       --> 16;       ! For parser to write its results in
  179. Global parser_inflection;            ! A property (usually "name") to find
  180.                                      ! object names in
  181. ! ------------------------------------------------------------------------------
  182. !   Parser output
  183. ! ------------------------------------------------------------------------------
  184. Global actor;                        ! Person asked to do something
  185. Global actors_location;              ! Like location, but for the actor
  186. Global meta;                         ! Verb is a meta-command (such as "save")
  187.  
  188. Array  multiple_object --> 64;       ! List of multiple parameters
  189. Global multiflag;                    ! Multiple-object flag
  190. Global toomany_flag;                 ! Flag for "multiple match too large"
  191.                                      ! (e.g. if "take all" took over 100 things)
  192.  
  193. Global special_word;                 ! Dictionary address for "special" token
  194. Global special_number;               ! Number typed for "special" token
  195. Global parsed_number;                ! For user-supplied parsing routines
  196. Global consult_from;                 ! Word that a "consult" topic starts on
  197. Global consult_words;                ! ...and number of words in topic
  198. ! ------------------------------------------------------------------------------
  199. !   Implicit taking
  200. ! ------------------------------------------------------------------------------
  201. Global notheld_mode;                 ! To do with implicit taking
  202. Global onotheld_mode;                !     "old copy of notheld_mode", ditto
  203. Global not_holding;                  ! Object to be automatically taken as an
  204.                                      ! implicit command
  205. Array  kept_results --> 16;          ! Delayed command (while the take happens)
  206. ! ------------------------------------------------------------------------------
  207. !   Error numbers when parsing a grammar line
  208. ! ------------------------------------------------------------------------------
  209. Global etype;                        ! Error number on current line
  210. Global best_etype;                   ! Preferred error number so far
  211. Global nextbest_etype;               ! Preferred one, if ASKSCOPE_PE disallowed
  212.  
  213. Constant STUCK_PE     = 1;
  214. Constant UPTO_PE      = 2;
  215. Constant NUMBER_PE    = 3;
  216. Constant CANTSEE_PE   = 4;
  217. Constant TOOLIT_PE    = 5;
  218. Constant NOTHELD_PE   = 6;
  219. Constant MULTI_PE     = 7;
  220. Constant MMULTI_PE    = 8;
  221. Constant VAGUE_PE     = 9;
  222. Constant EXCEPT_PE    = 10;
  223. Constant ANIMA_PE     = 11;
  224. Constant VERB_PE      = 12;
  225. Constant SCENERY_PE   = 13;
  226. Constant ITGONE_PE    = 14;
  227. Constant JUNKAFTER_PE = 15;
  228. Constant TOOFEW_PE    = 16;
  229. Constant NOTHING_PE   = 17;
  230. Constant ASKSCOPE_PE  = 18;
  231. ! ------------------------------------------------------------------------------
  232. !   Pattern-matching against a single grammar line
  233. ! ------------------------------------------------------------------------------
  234. Array pattern --> 32;                ! For the current pattern match
  235. Global pcount;                       ! and a marker within it
  236. Array pattern2 --> 32;               ! And another, which stores the best match
  237. Global pcount2;                      ! so far
  238. Constant PATTERN_NULL = $ffff;       ! Entry for a token producing no text
  239.  
  240. Array  line_ttype-->32;              ! For storing an analysed grammar line
  241. Array  line_tdata-->32;
  242. Array  line_token-->32;
  243.  
  244. Global parameters;                   ! Parameters (objects) entered so far
  245. Global nsns;                         ! Number of special_numbers entered so far
  246. Global special_number1;              ! First number, if one was typed
  247. Global special_number2;              ! Second number, if two were typed
  248. ! ------------------------------------------------------------------------------
  249. !   Inferences and looking ahead
  250. ! ------------------------------------------------------------------------------
  251. Global params_wanted;                ! Number of parameters needed
  252.                                      ! (which may change in parsing)
  253.  
  254. Global inferfrom;                    ! The point from which the rest of the
  255.                                      ! command must be inferred
  256. Global inferword;                    ! And the preposition inferred
  257. Global dont_infer;                   ! Another dull flag
  258.  
  259. Global action_to_be;                 ! (If the current line were accepted.)
  260. Global action_reversed;              ! (Parameters would be reversed in order.)
  261. Global advance_warning;              ! What a later-named thing will be
  262. ! ------------------------------------------------------------------------------
  263. !   At the level of individual tokens now
  264. ! ------------------------------------------------------------------------------
  265. Global found_ttype;                  ! Used to break up tokens into type
  266. Global found_tdata;                  ! and data (by AnalyseToken)
  267. Global token_filter;                 ! For noun filtering by user routines
  268.  
  269. Global length_of_noun;               ! Set by NounDomain to no of words in noun
  270. Constant REPARSE_CODE = 10000;       ! Signals "reparse the text" as a reply
  271.                                      ! from NounDomain
  272.  
  273. Global lookahead;                    ! The token after the one now being matched
  274.  
  275. Global multi_mode;                   ! Multiple mode
  276. Global multi_wanted;                 ! Number of things needed in multitude
  277. Global multi_had;                    ! Number of things actually found
  278. Global multi_context;                ! What token the multi-obj was accepted for
  279.  
  280. Global indef_mode;                   ! "Indefinite" mode - ie, "take a brick"
  281.                                      ! is in this mode
  282. Global indef_type;                   ! Bit-map holding types of specification
  283. Global indef_wanted;                 ! Number of items wanted (100 for all)
  284. Global indef_guess_p;                ! Plural-guessing flag
  285. Global indef_owner;                  ! Object which must hold these items
  286. Global indef_cases;                  ! Possible gender and numbers of them
  287. Global indef_possambig;              ! Has a possibly dangerous assumption
  288.                                      ! been made about meaning of a descriptor?
  289. Global indef_nspec_at;               ! Word at which a number like "two" was
  290.                                      ! parsed (for backtracking)
  291. Global allow_plurals;                ! Whether plurals presently allowed or not
  292.  
  293. Global take_all_rule;                ! Slightly different rules apply to
  294.                                      ! "take all" than other uses of multiple
  295.                                      ! objects, to make adjudication produce
  296.                                      ! more pragmatically useful results
  297.                                      ! (Not a flag: possible values 0, 1, 2)
  298.  
  299. Global dict_flags_of_noun;           ! Of the noun currently being parsed
  300.                                      ! (a bitmap in #dict_par1 format)
  301. Global pronoun_word;                 ! Records which pronoun ("it", "them", ...)
  302.                                      ! caused an error
  303. Global pronoun_obj;                  ! And what obj it was thought to refer to
  304. Global pronoun__word;                ! Saved value
  305. Global pronoun__obj;                 ! Saved value
  306. ! ------------------------------------------------------------------------------
  307. !   Searching through scope and parsing "scope=Routine" grammar tokens
  308. ! ------------------------------------------------------------------------------
  309. Constant PARSING_REASON       = 0;   ! Possible reasons for searching scope
  310. Constant TALKING_REASON       = 1;
  311. Constant EACH_TURN_REASON     = 2;
  312. Constant REACT_BEFORE_REASON  = 3;
  313. Constant REACT_AFTER_REASON   = 4;
  314. Constant LOOPOVERSCOPE_REASON = 5;
  315. Constant TESTSCOPE_REASON     = 6;
  316.  
  317. Global scope_reason = PARSING_REASON; ! Current reason for searching scope
  318.  
  319. Global scope_token;                  ! For "scope=Routine" grammar tokens
  320. Global scope_error;
  321. Global scope_stage;                  ! 1, 2 then 3
  322.  
  323. Global ats_flag = 0;                 ! For AddToScope routines
  324. Global ats_hls;                      !
  325.  
  326. Global placed_in_flag;               ! To do with PlaceInScope
  327.  
  328. ! ------------------------------------------------------------------------------
  329. !   The match list of candidate objects for a given token
  330. ! ------------------------------------------------------------------------------
  331. Constant MATCH_LIST_SIZE = 128;
  332. Array  match_list    --> 64;         ! An array of matched objects so far
  333. Array  match_classes --> 64;         ! An array of equivalence classes for them
  334. Array  match_scores --> 64;          ! An array of match scores for them
  335. Global number_matched;               ! How many items in it?  (0 means none)
  336. Global number_of_classes;            ! How many equivalence classes?
  337. Global match_length;                 ! How many words long are these matches?
  338. Global match_from;                   ! At what word of the input do they begin?
  339. ! ------------------------------------------------------------------------------
  340. !   Low level textual manipulation
  341. ! ------------------------------------------------------------------------------
  342. Array  buffer    string 120;         ! Buffer for parsing main line of input
  343. Array  parse     string 64;          ! Parse table mirroring it
  344. Array  buffer2   string 120;         ! Buffers for supplementary questions
  345. Array  parse2    string 64;          !
  346. Array  buffer3   string 120;         ! Buffer retaining input for "again"
  347.  
  348. Constant comma_word = 'comma,';      ! An "untypeable word" used to substitute
  349.                                      ! for commas in parse buffers
  350.  
  351. Global wn;                           ! Word number within "parse" (from 1)
  352. Global num_words;                    ! Number of words typed
  353. Global verb_word;                    ! Verb word (eg, take in "take all" or
  354.                                      ! "dwarf, take all") - address in dict
  355. Global verb_wordnum;                 ! its number in typing order (eg, 1 or 3)
  356. Global usual_grammar_after;          ! Point from which usual grammar is parsed
  357.                                      ! (it may vary from the above if user's
  358.                                      ! routines match multi-word verbs)
  359.  
  360. Global oops_from;                    ! The "first mistake" word number
  361. Global saved_oops;                   ! Used in working this out
  362. Array  oops_workspace -> 64;         ! Used temporarily by "oops" routine
  363.  
  364. Global held_back_mode;               ! Flag: is there some input from last time
  365. Global hb_wn;                        ! left over?  (And a save value for wn.)
  366.                                      ! (Used for full stops and "then".)
  367. ! ----------------------------------------------------------------------------
  368. Array PowersOfTwo_TB                 ! Used in converting case numbers to
  369.   --> $$100000000000                 ! case bitmaps
  370.       $$010000000000
  371.       $$001000000000
  372.       $$000100000000
  373.       $$000010000000
  374.       $$000001000000
  375.       $$000000100000
  376.       $$000000010000
  377.       $$000000001000
  378.       $$000000000100
  379.       $$000000000010
  380.       $$000000000001;
  381. ! ============================================================================
  382.  
  383.  
  384. ! ============================================================================
  385. !  Constants, and one variable, needed for the language definition file
  386. ! ----------------------------------------------------------------------------
  387. Constant POSSESS_PK  = $100;
  388. Constant DEFART_PK   = $101;
  389. Constant INDEFART_PK = $102;
  390. Global short_name_case;
  391. ! ----------------------------------------------------------------------------
  392. Include "language__";                !  The natural language definition,
  393.                                      !  whose filename is taken from the ICL
  394.                                      !  language_name variable
  395. ! ----------------------------------------------------------------------------
  396. #ifndef LanguageCases;
  397. Constant LanguageCases = 1;
  398. #endif;
  399. ! ------------------------------------------------------------------------------
  400. !   Pronouns support for the cruder (library 6/2 and earlier) version:
  401. !   only needed in English
  402. ! ------------------------------------------------------------------------------
  403. #ifdef EnglishNaturalLanguage;
  404. Global itobj = NULL;                 ! The object which is currently "it"
  405. Global himobj = NULL;                ! The object which is currently "him"
  406. Global herobj = NULL;                ! The object which is currently "her"
  407.  
  408. Global old_itobj = NULL;             ! The object which is currently "it"
  409. Global old_himobj = NULL;            ! The object which is currently "him"
  410. Global old_herobj = NULL;            ! The object which is currently "her"
  411. #endif;
  412. ! ============================================================================
  413.  
  414.  
  415. ! ============================================================================
  416. ! "Darkness" is not really a place: but it has to be an object so that the
  417. !  location-name on the status line can be "Darkness".
  418. ! ----------------------------------------------------------------------------
  419. Object thedark "(darkness object)"
  420.   with initial 0,
  421.        short_name DARKNESS__TX,
  422.        description
  423.        [;  return L__M(##Miscellany, 17);
  424.        ];
  425. Object selfobj "(self object)"
  426.   with short_name
  427.        [;  return L__M(##Miscellany, 18);
  428.        ],
  429.        description
  430.        [;  return L__M(##Miscellany, 19);
  431.        ],
  432.        before NULL,   after NULL,    life NULL,    each_turn NULL,
  433.        time_out NULL, describe NULL,
  434.        capacity 100, parse_name 0,
  435.        orders 0, number 0,
  436.   has  concealed animate proper transparent;
  437.  
  438. ! ============================================================================
  439. !  The definition of the token-numbering system used by Inform.
  440. ! ----------------------------------------------------------------------------
  441.  
  442. Constant ILLEGAL_TT        = 0;      ! Types of grammar token: illegal
  443. Constant ELEMENTARY_TT     = 1;      !     (one of those below)
  444. Constant PREPOSITION_TT    = 2;      !     e.g. 'into'
  445. Constant ROUTINE_FILTER_TT = 3;      !     e.g. noun=CagedCreature
  446. Constant ATTR_FILTER_TT    = 4;      !     e.g. edible
  447. Constant SCOPE_TT          = 5;      !     e.g. scope=Spells
  448. Constant GPR_TT            = 6;      !     a general parsing routine
  449.  
  450. Constant NOUN_TOKEN        = 0;      ! The elementary grammar tokens, and
  451. Constant HELD_TOKEN        = 1;      ! the numbers compiled by Inform to
  452. Constant MULTI_TOKEN       = 2;      ! encode them
  453. Constant MULTIHELD_TOKEN   = 3;
  454. Constant MULTIEXCEPT_TOKEN = 4;
  455. Constant MULTIINSIDE_TOKEN = 5;
  456. Constant CREATURE_TOKEN    = 6;
  457. Constant SPECIAL_TOKEN     = 7;
  458. Constant NUMBER_TOKEN      = 8;
  459. Constant TOPIC_TOKEN       = 9;
  460.  
  461. Constant GPR_FAIL          = -1;     ! Return values from General Parsing
  462. Constant GPR_PREPOSITION   = 0;      ! Routines
  463. Constant GPR_NUMBER        = 1;
  464. Constant GPR_REPARSE       = REPARSE_CODE;
  465. Constant GPR_NOUN          = $ff00;
  466. Constant GPR_HELD          = $ff01;
  467. Constant GPR_MULTI         = $ff02;
  468. Constant GPR_MULTIHELD     = $ff03;
  469. Constant GPR_MULTIEXCEPT   = $ff04;
  470. Constant GPR_MULTIINSIDE   = $ff05;
  471. Constant GPR_CREATURE      = $ff06;
  472.  
  473. Constant ENDIT_TOKEN       = 15;     ! Value used to mean "end of grammar line"
  474.  
  475. #Iftrue Grammar__Version == 1;
  476. [ AnalyseToken token m;
  477.  
  478.     found_tdata = token;
  479.  
  480.     if (token < 0)   { found_ttype = ILLEGAL_TT; return; }
  481.     if (token <= 8)  { found_ttype = ELEMENTARY_TT; return; }
  482.     if (token < 15)  { found_ttype = ILLEGAL_TT; return; }
  483.     if (token == 15) { found_ttype = ELEMENTARY_TT; return; }
  484.     if (token < 48)  { found_ttype = ROUTINE_FILTER_TT;
  485.                        found_tdata = token - 16;
  486.                        return; }
  487.     if (token < 80)  { found_ttype = GPR_TT;
  488.                        found_tdata = #preactions_table-->(token-48);
  489.                        return; }
  490.     if (token < 128) { found_ttype = SCOPE_TT;
  491.                        found_tdata = #preactions_table-->(token-80);
  492.                        return; }
  493.     if (token < 180) { found_ttype = ATTR_FILTER_TT;
  494.                        found_tdata = token - 128;
  495.                        return; }
  496.  
  497.     found_ttype = PREPOSITION_TT;
  498.     m=#adjectives_table;
  499.     for (::)
  500.     {   if (token==m-->1) { found_tdata = m-->0; return; }
  501.         m=m+4;
  502.     }
  503.     m=#adjectives_table; RunTimeError(1);
  504.     found_tdata = m;
  505. ];
  506. [ UnpackGrammarLine line_address i m;
  507.   for (i = 0 : i < 32 : i++)
  508.   {   line_token-->i = ENDIT_TOKEN;
  509.       line_ttype-->i = ELEMENTARY_TT;
  510.       line_tdata-->i = ENDIT_TOKEN;
  511.   }
  512.   for (i = 0: i <= 5 :i++)
  513.   {   line_token-->i = line_address->(i+1);
  514.       AnalyseToken(line_token-->i);
  515.       if ((found_ttype == ELEMENTARY_TT) && (found_tdata == NOUN_TOKEN)
  516.           && (m == line_address->0))
  517.       {   line_token-->i = ENDIT_TOKEN;
  518.           break;
  519.       }
  520.       line_ttype-->i = found_ttype;
  521.       line_tdata-->i = found_tdata;
  522.       if (found_ttype ~= PREPOSITION_TT) m++;
  523.   }
  524.   action_to_be = line_address->7;
  525.   action_reversed = false;
  526.   params_wanted = line_address->0;
  527.   return line_address + 8;
  528. ];
  529. #Ifnot;
  530. [ AnalyseToken token;
  531.  
  532.     if (token == ENDIT_TOKEN)
  533.     {   found_ttype = ELEMENTARY_TT;
  534.         found_tdata = ENDIT_TOKEN;
  535.         return;
  536.     }
  537.  
  538.     found_ttype = (token->0) & $$1111;
  539.     found_tdata = (token+1)-->0;
  540. ];
  541. [ UnpackGrammarLine line_address i;
  542.   for (i = 0 : i < 32 : i++)
  543.   {   line_token-->i = ENDIT_TOKEN;
  544.       line_ttype-->i = ELEMENTARY_TT;
  545.       line_tdata-->i = ENDIT_TOKEN;
  546.   }
  547.   action_to_be = 256*(line_address->0) + line_address->1;
  548.   action_reversed = ((action_to_be & $400) ~= 0);
  549.   action_to_be = action_to_be & $3ff;
  550.   line_address--;
  551.   params_wanted = 0;
  552.   for (i=0::i++)
  553.   {   line_address = line_address + 3;
  554.       if (line_address->0 == ENDIT_TOKEN) break;
  555.       line_token-->i = line_address;
  556.       AnalyseToken(line_address);
  557.       if (found_ttype ~= PREPOSITION_TT) params_wanted++;
  558.       line_ttype-->i = found_ttype;
  559.       line_tdata-->i = found_tdata;
  560.   }
  561.   return line_address + 1;
  562. ];
  563. #Endif;
  564.  
  565. ! ============================================================================
  566. !  The InformParser object abstracts the front end of the parser.
  567. !
  568. !  InformParser.parse_input(results)
  569. !  returns only when a sensible request has been made, and puts into the
  570. !  "results" buffer:
  571. !
  572. !  --> 0 = The action number
  573. !  --> 1 = Number of parameters
  574. !  --> 2, 3, ... = The parameters (object numbers), but
  575. !                  0 means "put the multiple object list here"
  576. !                  1 means "put one of the special numbers here"
  577. !
  578. ! ----------------------------------------------------------------------------
  579.  
  580. Object InformParser "(Inform Parser)"
  581.   with parse_input
  582.        [ results; Parser__parse(results);
  583.        ], has proper;
  584.  
  585. ! ----------------------------------------------------------------------------
  586. !  The Keyboard routine actually receives the player's words,
  587. !  putting the words in "a_buffer" and their dictionary addresses in
  588. !  "a_table".  It is assumed that the table is the same one on each
  589. !  (standard) call.
  590. !
  591. !  It can also be used by miscellaneous routines in the game to ask
  592. !  yes-no questions and the like, without invoking the rest of the parser.
  593. !
  594. !  Return the number of words typed
  595. ! ----------------------------------------------------------------------------
  596.  
  597. [ Keyboard  a_buffer a_table  nw i w w2 x1 x2;
  598.  
  599.     DisplayStatus();
  600.     .FreshInput;
  601.  
  602. !  Save the start of the buffer, in case "oops" needs to restore it
  603. !  to the previous time's buffer
  604.  
  605.     for (i=0:i<64:i++) oops_workspace->i = a_buffer->i;
  606.  
  607. !  In case of an array entry corruption that shouldn't happen, but would be
  608. !  disastrous if it did:
  609.  
  610.    a_buffer->0 = 120;
  611.    a_table->0 = 64;
  612.  
  613. !  Print the prompt, and read in the words and dictionary addresses
  614.  
  615.     L__M(##Prompt);
  616.     AfterPrompt();
  617.     #IFV3; read a_buffer a_table; #ENDIF;
  618.     temp_global = 0;
  619.     #IFV5; read a_buffer a_table DrawStatusLine; #ENDIF;
  620.     nw=a_table->1;
  621.  
  622. !  If the line was blank, get a fresh line
  623.     if (nw == 0)
  624.     { L__M(##Miscellany,10); jump FreshInput; }
  625.  
  626. !  Unless the opening word was "oops", return
  627.  
  628.     w=a_table-->1;
  629.     if (w == OOPS1__WD or OOPS2__WD or OOPS3__WD) jump DoOops;
  630.  
  631. #IFV5;
  632. !  Undo handling
  633.  
  634.     if ((w == UNDO1__WD or UNDO2__WD or UNDO3__WD) && (parse->1==1))
  635.     {   if (turns==1)
  636.         {   L__M(##Miscellany,11); jump FreshInput;
  637.         }
  638.         if (undo_flag==0)
  639.         {   L__M(##Miscellany,6); jump FreshInput;
  640.         }
  641.         if (undo_flag==1) jump UndoFailed;
  642.         if (just_undone==1)
  643.         {   L__M(##Miscellany,12); jump FreshInput;
  644.         }
  645.         @restore_undo i;
  646.         if (i==0)
  647.         {   .UndoFailed;
  648.             L__M(##Miscellany,7);
  649.         }
  650.         jump FreshInput;
  651.     }
  652.     @save_undo i;
  653.     just_undone=0;
  654.     undo_flag=2;
  655.     if (i==-1) undo_flag=0;
  656.     if (i==0) undo_flag=1;
  657.     if (i==2)
  658.     {   style bold;
  659.         print (name) location, "^";
  660.         style roman;
  661.         L__M(##Miscellany,13);
  662.         just_undone=1;
  663.         jump FreshInput;
  664.     }
  665. #ENDIF;
  666.  
  667.     return nw;
  668.  
  669.     .DoOops;
  670.     if (oops_from == 0)
  671.     {   L__M(##Miscellany,14); jump FreshInput; }
  672.     if (nw == 1)
  673.     {   L__M(##Miscellany,15); jump FreshInput; }
  674.     if (nw > 2)
  675.     {   L__M(##Miscellany,16); jump FreshInput; }
  676.  
  677. !  So now we know: there was a previous mistake, and the player has
  678. !  attempted to correct a single word of it.
  679.  
  680.     for (i=0:i<=120:i++) buffer2->i = a_buffer->i;
  681.     x1 = a_table->9; ! Start of word following "oops"
  682.     x2 = a_table->8; ! Length of word following "oops"
  683.  
  684. !  Repair the buffer to the text that was in it before the "oops"
  685. !  was typed:
  686.  
  687.     for (i=0:i<64:i++) a_buffer->i = oops_workspace->i;
  688.     @tokenise a_buffer a_table;
  689.  
  690. !  Work out the position in the buffer of the word to be corrected:
  691.  
  692.     w = a_table->(4*oops_from + 1); ! Start of word to go
  693.     w2 = a_table->(4*oops_from);    ! Length of word to go
  694.  
  695. !  Write spaces over the word to be corrected:
  696.  
  697.     for (i=0:i<w2:i++) a_buffer->(i+w) = ' ';
  698.  
  699.     if (w2 < x2)
  700.     {   ! If the replacement is longer than the original, move up...
  701.  
  702.         for (i=120:i>=w+x2:i--)
  703.             a_buffer->i = a_buffer->(i-x2+w2);
  704.  
  705.         ! ...increasing buffer size accordingly.
  706.  
  707.         a_buffer->1 = (a_buffer->1) + (x2-w2);
  708.     }
  709.  
  710. !  Write the correction in:
  711.  
  712.     for (i=0:i<x2:i++) a_buffer->(i+w) = buffer2->(i+x1);
  713.  
  714.     @tokenise a_buffer a_table;
  715.     nw=a_table->1;
  716.  
  717.     return nw;
  718. ];
  719.  
  720. ! ----------------------------------------------------------------------------
  721. !  To simplify the picture a little, a rough map of the main routine:
  722. !
  723. !  (A)    Get the input, do "oops" and "again"
  724. !  (B)    Is it a direction, and so an implicit "go"?  If so go to (K)
  725. !  (C)    Is anyone being addressed?
  726. !  (D)    Get the verb: try all the syntax lines for that verb
  727. !  (E)    Break down a syntax line into analysed tokens
  728. !  (F)    Look ahead for advance warning for multiexcept/multiinside
  729. !  (G)    Parse each token in turn (calling ParseToken to do most of the work)
  730. !  (H)    Cheaply parse otherwise unrecognised conversation and return
  731. !  (I)    Print best possible error message
  732. !  (J)    Retry the whole lot
  733. !  (K)    Last thing: check for "then" and further instructions(s), return.
  734. !
  735. !  The strategic points (A) to (K) are marked in the commentary.
  736. !
  737. !  Note that there are three different places where a return can happen.
  738. ! ----------------------------------------------------------------------------
  739.  
  740. [ Parser__parse  results   syntax line num_lines line_address i j k
  741.                            token l m;
  742.  
  743. !  **** (A) ****
  744.  
  745. !  Firstly, in "not held" mode, we still have a command left over from last
  746. !  time (eg, the user typed "eat biscuit", which was parsed as "take biscuit"
  747. !  last time, with "eat biscuit" tucked away until now).  So we return that.
  748.  
  749.     if (notheld_mode==1)
  750.     {   for (i=0:i<8:i++) results-->i=kept_results-->i;
  751.         notheld_mode=0; rtrue;
  752.     }
  753.  
  754.     if (held_back_mode==1)
  755.     {   held_back_mode=0;
  756.         @tokenise buffer parse;
  757.         jump ReParse;
  758.     }
  759.  
  760.   .ReType;
  761.  
  762.     Keyboard(buffer,parse);
  763.  
  764.   .ReParse;
  765.  
  766.     parser_inflection = name;
  767.  
  768. !  Initially assume the command is aimed at the player, and the verb
  769. !  is the first word
  770.  
  771.     num_words=parse->1;
  772.     wn=1;
  773. #ifdef LanguageToInformese;
  774.     LanguageToInformese();
  775. #ifv5;
  776. !   Re-tokenise:
  777.     @tokenise buffer parse;
  778. #endif;
  779. #endif;
  780.  
  781.     BeforeParsing();
  782.     num_words=parse->1;
  783.  
  784.     k=0;
  785. #ifdef DEBUG;
  786.     if (parser_trace>=2)
  787.     {   print "[ ";
  788.         for (i=0:i<num_words:i++)
  789.         {   j=parse-->(i*2 + 1);
  790.             k=WordAddress(i+1);
  791.             l=WordLength(i+1);
  792.             print "~"; for (m=0:m<l:m++) print (char) k->m; print "~ ";
  793.  
  794.             if (j == 0) print "?";
  795.             else
  796.             {   if (UnsignedCompare(j, 0-->4)>=0
  797.                     && UnsignedCompare(j, 0-->2)<0) print (address) j;
  798.                 else print j;
  799.             }
  800.             if (i ~= num_words-1) print " / ";
  801.         }
  802.         print " ]^";
  803.     }
  804. #endif;
  805.     verb_wordnum=1;
  806.     actor=player;
  807.     actors_location = ScopeCeiling(player);
  808.     usual_grammar_after = 0;
  809.  
  810.   .AlmostReParse;
  811.  
  812.     scope_token = 0;
  813.     action_to_be = NULL;
  814.  
  815. !  Begin from what we currently think is the verb word
  816.  
  817.   .BeginCommand;
  818.     wn=verb_wordnum;
  819.     verb_word = NextWordStopped();
  820.  
  821. !  If there's no input here, we must have something like
  822. !  "person,".
  823.  
  824.     if (verb_word==-1)
  825.     {   best_etype = STUCK_PE; jump GiveError; }
  826.  
  827. !  Now try for "again" or "g", which are special cases:
  828. !  don't allow "again" if nothing has previously been typed;
  829. !  simply copy the previous text across
  830.  
  831.     if (verb_word==AGAIN2__WD or AGAIN3__WD) verb_word=AGAIN1__WD;
  832.     if (verb_word==AGAIN1__WD)
  833.     {   if (actor~=player)
  834.         {   L__M(##Miscellany,20); jump ReType; }
  835.         if (buffer3->1==0)
  836.         {   L__M(##Miscellany,21); jump ReType; }
  837.         for (i=0:i<120:i++) buffer->i=buffer3->i;
  838.         jump ReParse;
  839.     }
  840.  
  841. !  Save the present input in case of an "again" next time
  842.  
  843.     if (verb_word~=AGAIN1__WD)
  844.         for (i=0:i<120:i++) buffer3->i=buffer->i;
  845.  
  846.     if (usual_grammar_after==0)
  847.     {   i = RunRoutines(actor, grammar);
  848.         #ifdef DEBUG;
  849.         if (parser_trace>=2 && actor.grammar~=0 or NULL)
  850.             print " [Grammar property returned ", i, "]^";
  851.         #endif;
  852.         if (i<0) { usual_grammar_after = verb_wordnum; i=-i; }
  853.         if (i==1)
  854.         {   results-->0 = action;
  855.             results-->1 = noun;
  856.             results-->2 = second;
  857.             rtrue;
  858.         }
  859.         if (i~=0) { verb_word = i; wn--; verb_wordnum--; }
  860.         else
  861.         {   wn = verb_wordnum; verb_word=NextWord();
  862.         }
  863.     }
  864.     else usual_grammar_after=0;
  865.  
  866. !  **** (B) ****
  867.  
  868.     #ifdef LanguageIsVerb;
  869.     if (verb_word==0)
  870.     {   i = wn; verb_word=LanguageIsVerb(buffer, parse, verb_wordnum);
  871.         wn = i;
  872.     }
  873.     #endif;
  874.  
  875. !  If the first word is not listed as a verb, it must be a direction
  876. !  or the name of someone to talk to
  877.  
  878.     if (verb_word==0 || ((verb_word->#dict_par1) & 1) == 0)
  879.     {   
  880.  
  881. !  So is the first word an object contained in the special object "compass"
  882. !  (i.e., a direction)?  This needs use of NounDomain, a routine which
  883. !  does the object matching, returning the object number, or 0 if none found,
  884. !  or REPARSE_CODE if it has restructured the parse table so the whole parse
  885. !  must be begun again...
  886.  
  887.         wn=verb_wordnum; indef_mode = false; token_filter = 0;
  888.         l=NounDomain(compass,0,0); if (l==REPARSE_CODE) jump ReParse;
  889.  
  890. !  If it is a direction, send back the results:
  891. !  action=GoSub, no of arguments=1, argument 1=the direction.
  892.  
  893.         if (l~=0)
  894.         {   results-->0 = ##Go;
  895.             results-->1 = 1;
  896.             results-->2 = l;
  897.             jump LookForMore;
  898.         }
  899.  
  900. !  **** (C) ****
  901.  
  902. !  Only check for a comma (a "someone, do something" command) if we are
  903. !  not already in the middle of one.  (This simplification stops us from
  904. !  worrying about "robot, wizard, you are an idiot", telling the robot to
  905. !  tell the wizard that she is an idiot.)
  906.  
  907.         if (actor==player)
  908.         {   for (j=2:j<=num_words:j++)
  909.             {   i=NextWord(); if (i==comma_word) jump Conversation;
  910.             }
  911.  
  912.             verb_word=UnknownVerb(verb_word);
  913.             if (verb_word~=0) jump VerbAccepted;
  914.         }
  915.  
  916.         best_etype=VERB_PE; jump GiveError;
  917.  
  918. !  NextWord nudges the word number wn on by one each time, so we've now
  919. !  advanced past a comma.  (A comma is a word all on its own in the table.)
  920.  
  921.       .Conversation;
  922.         j=wn-1;
  923.         if (j==1) { L__M(##Miscellany,22); jump ReType; }
  924.  
  925. !  Use NounDomain (in the context of "animate creature") to see if the
  926. !  words make sense as the name of someone held or nearby
  927.  
  928.         wn=1; lookahead=HELD_TOKEN;
  929.         scope_reason = TALKING_REASON;
  930.         l=NounDomain(player,actors_location,6);
  931.         scope_reason = PARSING_REASON;
  932.         if (l==REPARSE_CODE) jump ReParse;
  933.  
  934.         if (l==0) { L__M(##Miscellany,23); jump ReType; }
  935.  
  936. !  The object addressed must at least be "talkable" if not actually "animate"
  937. !  (the distinction allows, for instance, a microphone to be spoken to,
  938. !  without the parser thinking that the microphone is human).
  939.  
  940.         if (l hasnt animate && l hasnt talkable)
  941.         {   L__M(##Miscellany, 24, l); jump ReType; }
  942.  
  943. !  Check that there aren't any mystery words between the end of the person's
  944. !  name and the comma (eg, throw out "dwarf sdfgsdgs, go north").
  945.  
  946.         if (wn~=j)
  947.         {   L__M(##Miscellany, 25); jump ReType; }
  948.  
  949. !  The player has now successfully named someone.  Adjust "him", "her", "it":
  950.  
  951.         PronounNotice(l);
  952.  
  953. !  Set the global variable "actor", adjust the number of the first word,
  954. !  and begin parsing again from there.
  955.  
  956.         verb_wordnum=j+1; actor=l;
  957.         actors_location=ScopeCeiling(l);
  958.         #ifdef DEBUG;
  959.         if (parser_trace>=1)
  960.             print "[Actor is ", (the) actor, " in ",
  961.                 (name) actors_location, "]^";
  962.         #endif;
  963.         jump BeginCommand;
  964.     }
  965.  
  966. !  **** (D) ****
  967.  
  968.    .VerbAccepted;
  969.  
  970. !  We now definitely have a verb, not a direction, whether we got here by the
  971. !  "take ..." or "person, take ..." method.  Get the meta flag for this verb:
  972.  
  973.     meta=((verb_word->#dict_par1) & 2)/2;
  974.  
  975. !  You can't order other people to "full score" for you, and so on...
  976.  
  977.     if (meta==1 && actor~=player)
  978.     {   best_etype=VERB_PE; meta=0; jump GiveError; }
  979.  
  980. !  Now let i be the corresponding verb number, stored in the dictionary entry
  981. !  (in a peculiar 255-n fashion for traditional Infocom reasons)...
  982.  
  983.     i=$ff-(verb_word->#dict_par2);
  984.  
  985. !  ...then look up the i-th entry in the verb table, whose address is at word
  986. !  7 in the Z-machine (in the header), so as to get the address of the syntax
  987. !  table for the given verb...
  988.  
  989.     syntax=(0-->7)-->i;
  990.  
  991. !  ...and then see how many lines (ie, different patterns corresponding to the
  992. !  same verb) are stored in the parse table...
  993.  
  994.     num_lines=(syntax->0)-1;
  995.  
  996. !  ...and now go through them all, one by one.
  997. !  To prevent pronoun_word 0 being misunderstood,
  998.  
  999.    pronoun_word=NULL; pronoun_obj=NULL;
  1000.  
  1001.    #ifdef DEBUG;
  1002.    if (parser_trace>=1)
  1003.    {    print "[Parsing for the verb '", (address) verb_word,
  1004.               "' (", num_lines+1, " lines)]^";
  1005.    }
  1006.    #endif;
  1007.  
  1008.    best_etype=STUCK_PE; nextbest_etype=STUCK_PE;
  1009.  
  1010. !  "best_etype" is the current failure-to-match error - it is by default
  1011. !  the least informative one, "don't understand that sentence".
  1012. !  "nextbest_etype" remembers the best alternative to having to ask a
  1013. !  scope token for an error message (i.e., the best not counting ASKSCOPE_PE).
  1014.  
  1015.  
  1016. !  **** (E) ****
  1017.  
  1018.     line_address = syntax + 1;
  1019.  
  1020.     for (line=0:line<=num_lines:line++)
  1021.     {   
  1022.         for (i = 0 : i < 32 : i++)
  1023.         {   line_token-->i = ENDIT_TOKEN;
  1024.             line_ttype-->i = ELEMENTARY_TT;
  1025.             line_tdata-->i = ENDIT_TOKEN;
  1026.         }
  1027.  
  1028. !  Unpack the syntax line from Inform format into three arrays; ensure that
  1029. !  the sequence of tokens ends in an ENDIT_TOKEN.
  1030.  
  1031.         line_address = UnpackGrammarLine(line_address);
  1032.             
  1033.         #ifdef DEBUG;
  1034.         if (parser_trace >= 1)
  1035.         {   if (parser_trace >= 2) new_line;
  1036.             print "[line ", line; DebugGrammarLine();
  1037.             print "]^";
  1038.         }
  1039.         #endif;
  1040.  
  1041. !  We aren't in "not holding" or inferring modes, and haven't entered
  1042. !  any parameters on the line yet, or any special numbers; the multiple
  1043. !  object is still empty.
  1044.  
  1045.         not_holding=0;
  1046.         inferfrom=0;
  1047.         parameters=0;
  1048.         nsns=0; special_word=0; special_number=0;
  1049.         multiple_object-->0 = 0;
  1050.         multi_context = 0;
  1051.         etype=STUCK_PE;
  1052.  
  1053. !  Put the word marker back to just after the verb
  1054.  
  1055.         wn=verb_wordnum+1;
  1056.  
  1057. !  **** (F) ****
  1058. !  There are two special cases where parsing a token now has to be
  1059. !  affected by the result of parsing another token later, and these
  1060. !  two cases (multiexcept and multiinside tokens) are helped by a quick
  1061. !  look ahead, to work out the future token now.  We can only carry this
  1062. !  out in the simple (but by far the most common) case:
  1063. !
  1064. !      multiexcept <one or more prepositions> noun
  1065. !
  1066. !  and similarly for multiinside.
  1067.  
  1068.         advance_warning = NULL; indef_mode = false;
  1069.         for (i=0,m=false,pcount=0:line_token-->pcount ~= ENDIT_TOKEN:pcount++)
  1070.         {   scope_token = 0;
  1071.  
  1072.             if (line_ttype-->pcount ~= PREPOSITION_TT) i++;
  1073.  
  1074.             if (line_ttype-->pcount == ELEMENTARY_TT)
  1075.             {   if (line_tdata-->pcount == MULTI_TOKEN) m=true;
  1076.                 if (line_tdata-->pcount
  1077.                     == MULTIEXCEPT_TOKEN or MULTIINSIDE_TOKEN  && i==1)
  1078.                 {   !   First non-preposition is "multiexcept" or
  1079.                     !   "multiinside", so look ahead.
  1080.  
  1081.                     #ifdef DEBUG;
  1082.                     if (parser_trace>=2) print " [Trying look-ahead]^";
  1083.                     #endif;
  1084.  
  1085.                     !   We need this to be followed by 1 or more prepositions.
  1086.  
  1087.                     pcount++;
  1088.                     if (line_ttype-->pcount == PREPOSITION_TT)
  1089.                     {   while (line_ttype-->pcount == PREPOSITION_TT)
  1090.                             pcount++;
  1091.  
  1092.                         if ((line_ttype-->pcount == ELEMENTARY_TT)
  1093.                             && (line_tdata-->pcount == NOUN_TOKEN))
  1094.                         {
  1095.                             !  Advance past the last preposition
  1096.  
  1097.                             while (wn <= num_words)
  1098.                             {   if (NextWord() == line_tdata-->(pcount-1))
  1099.                                 {   l = NounDomain(actors_location, actor,
  1100.                                             NOUN_TOKEN);
  1101.                                     #ifdef DEBUG;
  1102.                                     if (parser_trace>=2)
  1103.                                     {   print " [Advanced to ~noun~ token: ";
  1104.                                         if (l==REPARSE_CODE)
  1105.                                             print "re-parse request]^";
  1106.                                         if (l==1) print "but multiple found]^";
  1107.                                         if (l==0) print "error ", etype, "]^";
  1108.                                         if (l>=2) print (the) l, "]^";
  1109.                                     }
  1110.                                     #endif;
  1111.                                     if (l==REPARSE_CODE) jump ReParse;
  1112.                                     if (l>=2) advance_warning = l;
  1113.                                 }
  1114.                             }
  1115.                         }
  1116.                     }
  1117.                     break;
  1118.                 }
  1119.             }
  1120.         }
  1121.  
  1122. !  Slightly different line-parsing rules will apply to "take multi", to
  1123. !  prevent "take all" behaving correctly but misleadingly when there's
  1124. !  nothing to take.
  1125.  
  1126.         take_all_rule = 0;
  1127.         if (m && params_wanted==1 && action_to_be==##Take)
  1128.             take_all_rule = 1;
  1129.  
  1130. !  And now start again, properly, forearmed or not as the case may be.
  1131. !  As a precaution, we clear all the variables again (they may have been
  1132. !  disturbed by the call to NounDomain, which may have called outside
  1133. !  code, which may have done anything!).
  1134.  
  1135.         not_holding=0;
  1136.         inferfrom=0;
  1137.         parameters=0;
  1138.         nsns=0; special_word=0; special_number=0;
  1139.         multiple_object-->0 = 0;
  1140.         etype=STUCK_PE;
  1141.         wn=verb_wordnum+1;
  1142.  
  1143. !  **** (G) ****
  1144. !  "Pattern" gradually accumulates what has been recognised so far,
  1145. !  so that it may be reprinted by the parser later on
  1146.  
  1147.         for (pcount=1::pcount++)
  1148.         {   pattern-->pcount = PATTERN_NULL; scope_token=0;
  1149.  
  1150.             token = line_token-->(pcount-1);
  1151.             lookahead = line_token-->pcount;
  1152.  
  1153.             #ifdef DEBUG;
  1154.             if (parser_trace >= 2)
  1155.                print " [line ", line, " token ", pcount, " word ", wn, " : ",
  1156.                      (DebugToken) token, "]^";
  1157.             #endif;
  1158.  
  1159.             if (token ~= ENDIT_TOKEN)
  1160.             {   scope_reason = PARSING_REASON;
  1161.                 l = ParseToken(results, pcount-1);
  1162.                 scope_reason = PARSING_REASON;
  1163.  
  1164.                 #ifdef DEBUG;
  1165.                 if (parser_trace >= 3)
  1166.                 {   print "  [token resulted in ";
  1167.                     if (l==REPARSE_CODE) print " re-parse request]^";
  1168.                     if (l==0) print " failure with error type ", etype, "]^";
  1169.                     if (l==1) print " success]^";
  1170.                 }
  1171.                 #endif;
  1172.  
  1173.                 if (l==REPARSE_CODE) jump ReParse;
  1174.                 if (l==0)    break;
  1175.             }
  1176.             else
  1177.             {
  1178.  
  1179. !  If the player has entered enough already but there's still
  1180. !  text to wade through: store the pattern away so as to be able to produce
  1181. !  a decent error message if this turns out to be the best we ever manage,
  1182. !  and in the mean time give up on this line
  1183.  
  1184. !  However, if the superfluous text begins with a comma or "then" then
  1185. !  take that to be the start of another instruction
  1186.  
  1187.                 if (wn <= num_words)
  1188.                 {   l=NextWord();
  1189.                     if (l==THEN1__WD or THEN2__WD or THEN3__WD or comma_word)
  1190.                     {   held_back_mode=1; hb_wn=wn-1; }
  1191.                     else
  1192.                     {   for (m=0:m<32:m++) pattern2-->m=pattern-->m;
  1193.                         pcount2=pcount;
  1194.                         etype=UPTO_PE; break;
  1195.                     }
  1196.                 }
  1197.  
  1198. !  Now, we may need to revise the multiple object because of the single one
  1199. !  we now know (but didn't when the list was drawn up).
  1200.  
  1201.                 if (parameters>=1 && results-->2 == 0)
  1202.                 {   l=ReviseMulti(results-->3);
  1203.                     if (l~=0) { etype=l; break; }
  1204.                 }
  1205.                 if (parameters>=2 && results-->3 == 0)
  1206.                 {   l=ReviseMulti(results-->2);
  1207.                     if (l~=0) { etype=l; break; }
  1208.                 }
  1209.  
  1210. !  To trap the case of "take all" inferring only "yourself" when absolutely
  1211. !  nothing else is in the vicinity...
  1212.  
  1213.                 if (take_all_rule==2 && results-->2 == actor)
  1214.                 {   best_etype = NOTHING_PE; jump GiveError;
  1215.                 }
  1216.  
  1217.                 #ifdef DEBUG;
  1218.                 if (parser_trace>=1)
  1219.                     print "[Line successfully parsed]^";
  1220.                 #endif;
  1221.  
  1222. !  The line has successfully matched the text.  Declare the input error-free...
  1223.  
  1224.                 oops_from = 0;
  1225.  
  1226. !  ...explain any inferences made (using the pattern)...
  1227.  
  1228.                 if (inferfrom~=0)
  1229.                 {   print "("; PrintCommand(inferfrom); print ")^";
  1230.                 }
  1231.  
  1232. !  ...copy the action number, and the number of parameters...
  1233.  
  1234.                 results-->0 = action_to_be;
  1235.                 results-->1 = parameters;
  1236.  
  1237. !  ...reverse first and second parameters if need be...
  1238.  
  1239.                 if (action_reversed && parameters==2)
  1240.                 {   i = results-->2; results-->2 = results-->3;
  1241.                     results-->3 = i;
  1242.                     if (nsns == 2)
  1243.                     {   i = special_number1; special_number1=special_number2;
  1244.                         special_number2=i;
  1245.                     }
  1246.                 }
  1247.  
  1248. !  ...and to reset "it"-style objects to the first of these parameters, if
  1249. !  there is one (and it really is an object)...
  1250.  
  1251.                 if (parameters > 0 && results-->2 >= 2)
  1252.                     PronounNotice(results-->2);
  1253.  
  1254. !  ...and worry about the case where an object was allowed as a parameter
  1255. !  even though the player wasn't holding it and should have been: in this
  1256. !  event, keep the results for next time round, go into "not holding" mode,
  1257. !  and for now tell the player what's happening and return a "take" request
  1258. !  instead...
  1259.  
  1260.                 if (not_holding~=0 && actor==player)
  1261.                 {   notheld_mode=1;
  1262.                     for (i=0:i<8:i++) kept_results-->i = results-->i;
  1263.                     results-->0 = ##Take;
  1264.                     results-->1 = 1;
  1265.                     results-->2 = not_holding;
  1266.                     L__M(##Miscellany, 26, not_holding);
  1267.                 }
  1268.  
  1269. !  (Notice that implicit takes are only generated for the player, and not
  1270. !  for other actors.  This avoids entirely logical, but misleading, text
  1271. !  being printed.)
  1272.  
  1273. !  ...and return from the parser altogether, having successfully matched
  1274. !  a line.
  1275.  
  1276.                 if (held_back_mode==1) { wn=hb_wn; jump LookForMore; }
  1277.                 rtrue;
  1278.             }
  1279.         }
  1280.  
  1281. !  The line has failed to match.
  1282. !  We continue the outer "for" loop, trying the next line in the grammar.
  1283.  
  1284.         if (etype>best_etype) best_etype=etype;
  1285.         if (etype~=ASKSCOPE_PE && etype>nextbest_etype) nextbest_etype=etype;
  1286.  
  1287. !  ...unless the line was something like "take all" which failed because
  1288. !  nothing matched the "all", in which case we stop and give an error now.
  1289.  
  1290.         if (take_all_rule == 2 && etype==NOTHING_PE) break;
  1291.    }
  1292.  
  1293. !  The grammar is exhausted: every line has failed to match.
  1294.  
  1295. !  **** (H) ****
  1296.  
  1297.   .GiveError;
  1298.         etype=best_etype;
  1299.  
  1300. !  Errors are handled differently depending on who was talking.
  1301.  
  1302. !  If the command was addressed to somebody else (eg, "dwarf, sfgh") then
  1303. !  it is taken as conversation which the parser has no business in disallowing.
  1304.  
  1305.     if (actor~=player)
  1306.     {   if (usual_grammar_after>0)
  1307.         {   verb_wordnum = usual_grammar_after;
  1308.             jump AlmostReParse;
  1309.         }
  1310.         wn=verb_wordnum;
  1311.         special_word=NextWord();
  1312.         if (special_word==comma_word)
  1313.         {   special_word=NextWord();
  1314.             verb_wordnum++;
  1315.         }
  1316.         special_number=TryNumber(verb_wordnum);
  1317.         results-->0=##NotUnderstood;
  1318.         results-->1=2;
  1319.         results-->2=1; special_number1=special_word;
  1320.         results-->3=actor;
  1321.         consult_from = verb_wordnum; consult_words = num_words-consult_from+1;
  1322.         rtrue;
  1323.     }
  1324.  
  1325. !  **** (I) ****
  1326.  
  1327. !  If the player was the actor (eg, in "take dfghh") the error must be printed,
  1328. !  and fresh input called for.  In three cases the oops word must be jiggled.
  1329.  
  1330.     if (ParserError(etype)~=0) jump ReType;
  1331.     pronoun_word = pronoun__word; pronoun_obj = pronoun__obj;
  1332.  
  1333.     if (etype==STUCK_PE)   { L__M(##Miscellany, 27); oops_from=1; }
  1334.     if (etype==UPTO_PE)    { L__M(##Miscellany, 28);
  1335.                              for (m=0:m<32:m++) pattern-->m = pattern2-->m;
  1336.                              pcount=pcount2; PrintCommand(0); print ".^";
  1337.                            }
  1338.     if (etype==NUMBER_PE)  L__M(##Miscellany, 29);
  1339.     if (etype==CANTSEE_PE) { L__M(##Miscellany, 30); oops_from=saved_oops; }
  1340.     if (etype==TOOLIT_PE)  L__M(##Miscellany, 31);
  1341.     if (etype==NOTHELD_PE) { L__M(##Miscellany, 32); oops_from=saved_oops; }
  1342.     if (etype==MULTI_PE)   L__M(##Miscellany, 33);
  1343.     if (etype==MMULTI_PE)  L__M(##Miscellany, 34);
  1344.     if (etype==VAGUE_PE)   L__M(##Miscellany, 35);
  1345.     if (etype==EXCEPT_PE)  L__M(##Miscellany, 36);
  1346.     if (etype==ANIMA_PE)   L__M(##Miscellany, 37);
  1347.     if (etype==VERB_PE)    L__M(##Miscellany, 38);
  1348.     if (etype==SCENERY_PE) L__M(##Miscellany, 39);
  1349.     if (etype==ITGONE_PE)
  1350.     {   if (pronoun_obj == NULL) L__M(##Miscellany, 35);
  1351.                             else L__M(##Miscellany, 40);
  1352.     }
  1353.     if (etype==JUNKAFTER_PE) L__M(##Miscellany, 41);
  1354.     if (etype==TOOFEW_PE)  L__M(##Miscellany, 42, multi_had);
  1355.     if (etype==NOTHING_PE) { if (multi_wanted==100) L__M(##Miscellany, 43);
  1356.                              else L__M(##Miscellany, 44);  }
  1357.  
  1358.     if (etype==ASKSCOPE_PE)
  1359.     {   scope_stage=3;
  1360.         if (indirect(scope_error)==-1)
  1361.         {   best_etype=nextbest_etype; jump GiveError;  }
  1362.     }
  1363.  
  1364. !  **** (J) ****
  1365.  
  1366. !  And go (almost) right back to square one...
  1367.  
  1368.     jump ReType;
  1369.  
  1370. !  ...being careful not to go all the way back, to avoid infinite repetition
  1371. !  of a deferred command causing an error.
  1372.  
  1373.  
  1374. !  **** (K) ****
  1375.  
  1376. !  At this point, the return value is all prepared, and we are only looking
  1377. !  to see if there is a "then" followed by subsequent instruction(s).
  1378.     
  1379.    .LookForMore;
  1380.  
  1381.    if (wn>num_words) rtrue;
  1382.  
  1383.    i=NextWord();
  1384.    if (i==THEN1__WD or THEN2__WD or THEN3__WD or comma_word)
  1385.    {   if (wn>num_words)
  1386.        {   held_back_mode = false; return; }
  1387.        i = WordAddress(verb_wordnum);
  1388.        j = WordAddress(wn);
  1389.        for (:i<j:i++) i->0 = ' ';
  1390.        i = NextWord();
  1391.        if (i==AGAIN1__WD or AGAIN2__WD or AGAIN3__WD)
  1392.        {   !   Delete the words "then again" from the again buffer,
  1393.            !   in which we have just realised that it must occur:
  1394.            !   prevents an infinite loop on "i. again"
  1395.  
  1396.            i = WordAddress(wn-2)-buffer;
  1397.            if (wn > num_words) j = 119; else j = WordAddress(wn)-buffer;
  1398.            for (:i<j:i++) buffer3->i = ' ';
  1399.        }
  1400.        @tokenise buffer parse; held_back_mode = true; return;
  1401.    }
  1402.    best_etype=UPTO_PE; jump GiveError;
  1403. ];
  1404.  
  1405. [ ScopeCeiling person act;
  1406.   act = parent(person);
  1407.   while (parent(act)~=0
  1408.          && (act has transparent || act has supporter
  1409.              || (act has container && act has open)))
  1410.       act = parent(act);
  1411.   if (person == player && location == thedark) return thedark;
  1412.   return act;
  1413. ];
  1414.  
  1415. ! ----------------------------------------------------------------------------
  1416. !  Descriptors()
  1417. !
  1418. !  Handles descriptive words like "my", "his", "another" and so on.
  1419. !  Skips "the", and leaves wn pointing to the first misunderstood word.
  1420. !
  1421. !  Allowed to set up for a plural only if allow_p is set
  1422. !
  1423. !  Returns error number, or 0 if no error occurred
  1424. ! ----------------------------------------------------------------------------
  1425.  
  1426. Constant OTHER_BIT  =   1;     !  These will be used in Adjudicate()
  1427. Constant MY_BIT     =   2;     !  to disambiguate choices
  1428. Constant THAT_BIT   =   4;
  1429. Constant PLURAL_BIT =   8;
  1430. Constant LIT_BIT    =  16;
  1431. Constant UNLIT_BIT  =  32;
  1432.  
  1433. [ ResetDescriptors;
  1434.    indef_mode=0; indef_type=0; indef_wanted=0; indef_guess_p=0;
  1435.    indef_possambig = false;
  1436.    indef_owner = nothing;
  1437.    indef_cases = $$111111111111;
  1438.    indef_nspec_at = 0;
  1439. ];
  1440.  
  1441. [ Descriptors allow_multiple  o x flag cto type n;
  1442.  
  1443.    ResetDescriptors();
  1444.    if (wn > num_words) return 0;
  1445.  
  1446.    for (flag=true:flag:)
  1447.    {   o=NextWordStopped(); flag=false;
  1448.  
  1449.        for (x=1:x<=LanguageDescriptors-->0:x=x+4)
  1450.            if (o == LanguageDescriptors-->x)
  1451.            {   flag = true;
  1452.                type = LanguageDescriptors-->(x+2);
  1453.                if (type ~= DEFART_PK) indef_mode = true;
  1454.                indef_possambig = true;
  1455.                indef_cases = indef_cases & (LanguageDescriptors-->(x+1));
  1456.  
  1457.                if (type == POSSESS_PK)
  1458.                {   cto = LanguageDescriptors-->(x+3);
  1459.                    switch(cto)
  1460.                    {  0: indef_type = indef_type | MY_BIT;
  1461.                       1: indef_type = indef_type | THAT_BIT;
  1462.                       default: indef_owner = PronounValue(cto);
  1463.                         if (indef_owner == NULL) indef_owner = InformParser;
  1464.                    }
  1465.                }
  1466.  
  1467.                if (type == light)
  1468.                    indef_type = indef_type | LIT_BIT;
  1469.                if (type == -light)
  1470.                    indef_type = indef_type | UNLIT_BIT;
  1471.            }
  1472.  
  1473.        if (o==OTHER1__WD or OTHER2__WD or OTHER3__WD)
  1474.                             { indef_mode=1; flag=1;
  1475.                               indef_type = indef_type | OTHER_BIT; }
  1476.        if (o==ALL1__WD or ALL2__WD or ALL3__WD or ALL4__WD or ALL5__WD)
  1477.                             { indef_mode=1; flag=1; indef_wanted=100;
  1478.                               if (take_all_rule == 1)
  1479.                                   take_all_rule = 2;
  1480.                               indef_type = indef_type | PLURAL_BIT; }
  1481.        if (allow_plurals && allow_multiple)
  1482.        {   n=NumberWord(o);
  1483.            if (n==1)        { indef_mode=1; flag=1; }
  1484.            if (n>1)         { indef_guess_p=1;
  1485.                               indef_mode=1; flag=1; indef_wanted=n;
  1486.                               indef_nspec_at=wn-1;
  1487.                               indef_type = indef_type | PLURAL_BIT; }
  1488.        }
  1489.        if (flag==1
  1490.            && NextWordStopped() ~= OF1__WD or OF2__WD or OF3__WD or OF4__WD)
  1491.            wn--;  ! Skip 'of' after these
  1492.    }
  1493.    wn--;
  1494.    if ((indef_wanted > 0) && (~~allow_multiple)) return MULTI_PE;
  1495.    return 0;
  1496. ];
  1497.  
  1498. ! ----------------------------------------------------------------------------
  1499. !  CreatureTest: Will this person do for a "creature" token?
  1500. ! ----------------------------------------------------------------------------
  1501.  
  1502. [ CreatureTest obj;
  1503.   if (obj has animate) rtrue;
  1504.   if (obj hasnt talkable) rfalse;
  1505.   if (action_to_be == ##Ask or ##Answer or ##Tell or ##AskFor) rtrue;
  1506.   rfalse;
  1507. ];
  1508.  
  1509. [ PrepositionChain wd index;
  1510.   if (line_tdata-->index == wd) return wd;
  1511.   if ((line_token-->index)->0 & $20 == 0) return -1;
  1512.   do
  1513.   {   if (line_tdata-->index == wd) return wd;
  1514.       index++;
  1515.   }
  1516.   until ((line_token-->index == ENDIT_TOKEN)
  1517.          || (((line_token-->index)->0 & $10) == 0));
  1518.   return -1;
  1519. ];
  1520.  
  1521. ! ----------------------------------------------------------------------------
  1522. !  ParseToken: Parses the given token, from the current word number wn
  1523. !
  1524. !  Returns:
  1525. !    REPARSE_CODE for "reconstructed input, please re-parse from scratch"
  1526. !    1            for "token accepted"
  1527. !    0            for "token failed"
  1528. !
  1529. !  (A)            Analyse the token; handle all tokens not involving
  1530. !                 object lists and break down others into elementary tokens
  1531. !  (B)            Begin parsing an object list
  1532. !  (C)            Parse descriptors (articles, pronouns, etc.) in the list
  1533. !  (D)            Parse an object name
  1534. !  (E)            Parse connectives ("and", "but", etc.) and go back to (C)
  1535. !  (F)            Return the conclusion of parsing an object list
  1536. ! ----------------------------------------------------------------------------
  1537.  
  1538. [ ParseToken results token_n token
  1539.              l o i j k and_parity single_object desc_wn many_flag
  1540.              token_allows_multiple;
  1541.  
  1542.    token = line_token-->token_n;
  1543.    AnalyseToken(token);
  1544.  
  1545. !  **** (A) ****
  1546.  
  1547.    token_filter = 0;
  1548.    parser_inflection = name;
  1549.  
  1550.    switch(found_ttype)
  1551.    {   ELEMENTARY_TT:
  1552.            switch(found_tdata)
  1553.            {   SPECIAL_TOKEN:
  1554.                    l=TryNumber(wn);
  1555.                    special_word=NextWord();
  1556.                    #ifdef DEBUG;
  1557.                    if (l~=-1000)
  1558.                        if (parser_trace>=3)
  1559.                            print "  [Read special as the number ", l, "]^";
  1560.                    #endif;
  1561.                    if (l==-1000)
  1562.                    {   #ifdef DEBUG;
  1563.                        if (parser_trace>=3)
  1564.                          print "  [Read special word at word number ", wn, "]^";
  1565.                        #endif;
  1566.                        l = special_word;
  1567.                    }
  1568.                    special_number=l;
  1569.                    if (nsns==0) special_number1=l; else special_number2=l;
  1570.                    nsns++;
  1571.                    single_object=1; jump PassToken;
  1572.  
  1573.                NUMBER_TOKEN:
  1574.                    l=TryNumber(wn++);
  1575.                    if (l==-1000) { etype=NUMBER_PE; rfalse; }
  1576.                    #ifdef DEBUG;
  1577.                    if (parser_trace>=3) print "  [Read number as ", l, "]^";
  1578.                    #endif;
  1579.                    if (nsns++==0) special_number1=l; else special_number2=l;
  1580.                    single_object=1; jump PassToken;
  1581.  
  1582.                CREATURE_TOKEN:
  1583.                    if (action_to_be==##Answer or ##Ask or ##AskFor or ##Tell)
  1584.                        scope_reason = TALKING_REASON;
  1585.  
  1586.                TOPIC_TOKEN:
  1587.                    consult_from = wn;
  1588.                    if ((line_ttype-->(token_n+1) ~= PREPOSITION_TT)
  1589.                        && (line_token-->(token_n+1) ~= ENDIT_TOKEN))
  1590.                        RunTimeError(13);
  1591.                    do o=NextWordStopped();
  1592.                    until (o==-1 || PrepositionChain(o, token_n+1) ~= -1);
  1593.                    wn--;
  1594.                    consult_words = wn-consult_from;
  1595.                    if (consult_words==0) return 1;
  1596.                    if (action_to_be==##Ask or ##Answer or ##Tell)
  1597.                    {   o=wn; wn=consult_from; parsed_number=NextWord();
  1598.                        if (parsed_number=='the' && consult_words>1)
  1599.                            parsed_number=NextWord();
  1600.                        wn=o;
  1601.                        if (nsns++==0) special_number1 = parsed_number;
  1602.                        else special_number2 = parsed_number;
  1603.                        single_object = 1; jump PassToken;
  1604.                    }
  1605.                    return 1;
  1606.            }
  1607.  
  1608.        PREPOSITION_TT:
  1609.            #Iffalse Grammar__Version==1;
  1610. !  Is it an unnecessary alternative preposition, when a previous choice
  1611. !  has already been matched?
  1612.            if ((token->0) & $10) return 1;
  1613.            #Endif;
  1614.  
  1615. !  If we've run out of the player's input, but still have parameters to
  1616. !  specify, we go into "infer" mode, remembering where we are and the
  1617. !  preposition we are inferring...
  1618.  
  1619.            if (wn > num_words)
  1620.            {   if (inferfrom==0 && parameters<params_wanted)
  1621.                {   inferfrom = pcount; inferword = token;
  1622.                    pattern-->pcount = REPARSE_CODE + Dword__No(found_tdata);
  1623.                }
  1624.  
  1625. !  If we are not inferring, then the line is wrong...
  1626.  
  1627.                if (inferfrom==0) return 0;
  1628.  
  1629. !  If not, then the line is right but we mark in the preposition...
  1630.  
  1631.                pattern-->pcount = REPARSE_CODE + Dword__No(found_tdata);
  1632.                return 1;
  1633.            }
  1634.  
  1635.            o = NextWord();
  1636.  
  1637.            pattern-->pcount = REPARSE_CODE + Dword__No(o);
  1638.  
  1639. !  Whereas, if the player has typed something here, see if it is the
  1640. !  required preposition... if it's wrong, the line must be wrong,
  1641. !  but if it's right, the token is passed (jump to finish this token).
  1642.  
  1643.            if (o == found_tdata) return 1;
  1644.            #Iffalse Grammar__Version==1;
  1645.            if (PrepositionChain(o, token_n) ~= -1) return 1;
  1646.            #Endif;
  1647.            return 0;
  1648.  
  1649.        GPR_TT:
  1650.            l=indirect(found_tdata);
  1651.            #ifdef DEBUG;
  1652.            if (parser_trace>=3)
  1653.                print "  [Outside parsing routine returned ", l, "]^";
  1654.            #endif;
  1655.            if (l<-200) { found_tdata = l + 256; break; }
  1656.            if (l<0) rfalse;
  1657.            if (l==GPR_PREPOSITION)
  1658.            {   params_wanted--; rtrue; }
  1659.            if (l==GPR_NUMBER)
  1660.            {   if (nsns==0) special_number1=parsed_number;
  1661.                else special_number2=parsed_number;
  1662.                nsns++;
  1663.            }
  1664.            if (l==GPR_REPARSE) return l;
  1665.            single_object=l; jump PassToken;
  1666.  
  1667.        SCOPE_TT:
  1668.            scope_token = found_tdata;
  1669.            scope_stage = 1;
  1670.            l = indirect(scope_token);
  1671.            #ifdef DEBUG;
  1672.            if (parser_trace>=3)
  1673.                print "  [Scope routine returned multiple-flag of ", l, "]^";
  1674.            #endif;
  1675.            if (l==1) found_tdata = MULTI_TOKEN; else found_tdata = NOUN_TOKEN;
  1676.  
  1677.        ATTR_FILTER_TT:
  1678.            token_filter = 1 + found_tdata;
  1679.            found_tdata = NOUN_TOKEN;
  1680.  
  1681.        ROUTINE_FILTER_TT:
  1682.            token_filter = found_tdata;
  1683.            found_tdata = NOUN_TOKEN;
  1684.    }
  1685.  
  1686.    token = found_tdata;
  1687.  
  1688. !  **** (B) ****
  1689.  
  1690. !  There are now three possible ways we can be here:
  1691. !      parsing an elementary token other than "special" or "number";
  1692. !      parsing a scope token;
  1693. !      parsing a noun-filter token (either by routine or attribute).
  1694. !
  1695. !  In each case, token holds the type of elementary parse to
  1696. !  perform in matching one or more objects, and
  1697. !  token_filter is 0 (default), an attribute + 1 for an attribute filter
  1698. !  or a routine address for a routine filter.
  1699.  
  1700.    token_allows_multiple = false;
  1701.    if (token == MULTI_TOKEN or MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
  1702.                 or MULTIINSIDE_TOKEN) token_allows_multiple = true;
  1703.  
  1704.    many_flag = false; and_parity = true; dont_infer = false;
  1705.  
  1706. !  **** (C) ****
  1707. !  We expect to find a list of objects next in what the player's typed.
  1708.  
  1709.   .ObjectList;
  1710.  
  1711.    #ifdef DEBUG;
  1712.    if (parser_trace>=3) print "  [Object list from word ", wn, "]^";
  1713.    #endif;
  1714.  
  1715. !  Take an advance look at the next word: if it's "it" or "them", and these
  1716. !  are unset, set the appropriate error number and give up on the line
  1717. !  (if not, these are still parsed in the usual way - it is not assumed
  1718. !  that they still refer to something in scope)
  1719.  
  1720.     o=NextWord(); wn--;
  1721.  
  1722.     pronoun_word = NULL; pronoun_obj = NULL;
  1723.     l = PronounValue(o);
  1724.     if (l ~= 0)
  1725.     {   pronoun_word = o; pronoun_obj = l;
  1726.         if (l == NULL)
  1727.         {   !   Don't assume this is a use of an unset pronoun until the
  1728.             !   descriptors have been checked, because it might be an
  1729.             !   article (or some such) instead
  1730.  
  1731.             for (l=1:l<=LanguageDescriptors:l=l+4)
  1732.                 if (o == LanguageDescriptors-->l) jump AssumeDescriptor;
  1733.             pronoun__word=pronoun_word; pronoun__obj=pronoun_obj;
  1734.             etype=VAGUE_PE; return 0;
  1735.         }
  1736.     }
  1737.  
  1738.     .AssumeDescriptor;
  1739.  
  1740.     if (o==ME1__WD or ME2__WD or ME3__WD)
  1741.     {   pronoun_word = o; pronoun_obj = player;
  1742.     }
  1743.  
  1744.     allow_plurals = true; desc_wn = wn;
  1745.  
  1746.     .TryAgain;
  1747. !   First, we parse any descriptive words (like "the", "five" or "every"):
  1748.     l = Descriptors(token_allows_multiple); if (l~=0) { etype=l; return 0; }
  1749.  
  1750.     .TryAgain2;
  1751.  
  1752. !  **** (D) ****
  1753.  
  1754. !  This is an actual specified object, and is therefore where a typing error
  1755. !  is most likely to occur, so we set:
  1756.  
  1757.     oops_from = wn;
  1758.  
  1759. !  So, two cases.  Case 1: token not equal to "held" (so, no implicit takes)
  1760. !  but we may well be dealing with multiple objects
  1761.  
  1762. !  In either case below we use NounDomain, giving it the token number as
  1763. !  context, and two places to look: among the actor's possessions, and in the
  1764. !  present location.  (Note that the order depends on which is likeliest.)
  1765.  
  1766.     if (token ~= HELD_TOKEN)
  1767.     {   i=multiple_object-->0;
  1768.         #ifdef DEBUG;
  1769.         if (parser_trace>=3)
  1770.             print "  [Calling NounDomain on location and actor]^";
  1771.         #endif;
  1772.         l=NounDomain(actors_location, actor, token);
  1773.         if (l==REPARSE_CODE) return l;                  ! Reparse after Q&A
  1774.         if (l==0) {   if (indef_possambig)
  1775.                       {   ResetDescriptors(); wn = desc_wn; jump TryAgain2; }
  1776.                       etype=CantSee(); jump FailToken; } ! Choose best error
  1777.  
  1778.         #ifdef DEBUG;
  1779.         if (parser_trace>=3)
  1780.         {   if (l>1)
  1781.                 print "  [ND returned ", (the) l, "]^";
  1782.             else
  1783.             {   print "  [ND appended to the multiple object list:^";
  1784.                 k=multiple_object-->0;
  1785.                 for (j=i+1:j<=k:j++)
  1786.                     print "  Entry ", j, ": ", (The) multiple_object-->j,
  1787.                           " (", multiple_object-->j, ")^";
  1788.                 print "  List now has size ", k, "]^";
  1789.             }
  1790.         }
  1791.         #endif;
  1792.  
  1793.         if (l==1)
  1794.         {   if (~~many_flag)
  1795.             {   many_flag = true;
  1796.             }
  1797.             else                                  ! Merge with earlier ones
  1798.             {   k=multiple_object-->0;            ! (with either parity)
  1799.                 multiple_object-->0 = i;
  1800.                 for (j=i+1:j<=k:j++)
  1801.                 {   if (and_parity) MultiAdd(multiple_object-->j);
  1802.                     else MultiSub(multiple_object-->j);
  1803.                 }
  1804.                 #ifdef DEBUG;
  1805.                 if (parser_trace>=3)
  1806.                     print "  [Merging ", k-i, " new objects to the ",
  1807.                         i, " old ones]^";
  1808.                 #endif;
  1809.             }
  1810.         }
  1811.         else
  1812.         {   ! A single object was indeed found
  1813.  
  1814.             if (match_length == 0 && indef_possambig)
  1815.             {   !   So the answer had to be inferred from no textual data,
  1816.                 !   and we know that there was an ambiguity in the descriptor
  1817.                 !   stage (such as a word which could be a pronoun being
  1818.                 !   parsed as an article or possessive).  It's worth having
  1819.                 !   another go.
  1820.  
  1821.                 ResetDescriptors(); wn = desc_wn; jump TryAgain2;
  1822.             }
  1823.         
  1824.             if (token==CREATURE_TOKEN && CreatureTest(l)==0)
  1825.             {   etype=ANIMA_PE; jump FailToken; } !  Animation is required
  1826.  
  1827.             if (~~many_flag)
  1828.                 single_object = l;
  1829.             else
  1830.             {   if (and_parity) MultiAdd(l); else MultiSub(l);
  1831.                 #ifdef DEBUG;
  1832.                 if (parser_trace>=3)
  1833.                     print "  [Combining ", (the) l, " with list]^";
  1834.                 #endif;
  1835.             }
  1836.         }
  1837.     }
  1838.  
  1839. !  Case 2: token is "held" (which fortunately can't take multiple objects)
  1840. !  and may generate an implicit take
  1841.  
  1842.     else
  1843.  
  1844.     {   l=NounDomain(actor,actors_location,token);       ! Same as above...
  1845.         if (l==REPARSE_CODE) return l;
  1846.         if (l==0)
  1847.         {   if (indef_possambig)
  1848.             {   ResetDescriptors(); wn = desc_wn; jump TryAgain2; }
  1849.             etype=CantSee(); return l;                   ! Choose best error
  1850.         }
  1851.  
  1852. !  ...until it produces something not held by the actor.  Then an implicit
  1853. !  take must be tried.  If this is already happening anyway, things are too
  1854. !  confused and we have to give up (but saving the oops marker so as to get
  1855. !  it on the right word afterwards).
  1856. !  The point of this last rule is that a sequence like
  1857. !
  1858. !      > read newspaper
  1859. !      (taking the newspaper first)
  1860. !      The dwarf unexpectedly prevents you from taking the newspaper!
  1861. !
  1862. !  should not be allowed to go into an infinite repeat - read becomes
  1863. !  take then read, but take has no effect, so read becomes take then read...
  1864. !  Anyway for now all we do is record the number of the object to take.
  1865.  
  1866.         o=parent(l);
  1867.         if (o~=actor)
  1868.         {   if (notheld_mode==1)
  1869.             {   saved_oops=oops_from; etype=NOTHELD_PE; jump FailToken;
  1870.             }
  1871.             not_holding = l;
  1872.             #ifdef DEBUG;
  1873.             if (parser_trace>=3)
  1874.                 print "  [Allowing object ", (the) l, " for now]^";
  1875.             #endif;
  1876.         }
  1877.         single_object = l;
  1878.     }
  1879.  
  1880. !  The following moves the word marker to just past the named object...
  1881.  
  1882.     wn = oops_from + match_length;
  1883.  
  1884. !  **** (E) ****
  1885.  
  1886. !  Object(s) specified now: is that the end of the list, or have we reached
  1887. !  "and", "but" and so on?  If so, create a multiple-object list if we
  1888. !  haven't already (and are allowed to).
  1889.  
  1890.     .NextInList;
  1891.  
  1892.     o=NextWord();
  1893.  
  1894.     if (o==AND1__WD or AND2__WD or AND3__WD or BUT1__WD or BUT2__WD or BUT3__WD
  1895.            or comma_word)
  1896.     {
  1897.         #ifdef DEBUG;
  1898.         if (parser_trace>=3) print "  [Read connective '", (address) o, "']^";
  1899.         #endif;
  1900.  
  1901.         if (~~token_allows_multiple)
  1902.         {   etype=MULTI_PE; jump FailToken;
  1903.         }
  1904.  
  1905.         if (o==BUT1__WD or BUT2__WD or BUT3__WD) and_parity = 1-and_parity;
  1906.  
  1907.         if (~~many_flag)
  1908.         {   multiple_object-->0 = 1;
  1909.             multiple_object-->1 = single_object;
  1910.             many_flag = true;
  1911.             #ifdef DEBUG;
  1912.             if (parser_trace>=3)
  1913.                 print "  [Making new list from ", (the) single_object, "]^";
  1914.             #endif;
  1915.         }
  1916.         dont_infer = true; inferfrom=0;           ! Don't print (inferences)
  1917.         jump ObjectList;                          ! And back around
  1918.     }
  1919.  
  1920.     wn--;   ! Word marker back to first not-understood word
  1921.  
  1922. !  **** (F) ****
  1923.  
  1924. !  Happy or unhappy endings:
  1925.  
  1926.     .PassToken;
  1927.  
  1928.     if (many_flag)
  1929.     {   single_object = 0;
  1930.         multi_context = token;
  1931.     }
  1932.     else
  1933.     {   if (indef_mode==1 && indef_type & PLURAL_BIT ~= 0)
  1934.         {   if (indef_wanted<100 && indef_wanted>1)
  1935.             {   multi_had=1; multi_wanted=indef_wanted;
  1936.                 etype=TOOFEW_PE;
  1937.                 jump FailToken;
  1938.             }
  1939.         }
  1940.     }
  1941.     results-->(parameters+2) = single_object;
  1942.     parameters++;
  1943.     pattern-->pcount = single_object;
  1944.     return 1;
  1945.  
  1946.     .FailToken;
  1947.  
  1948. !  If we were only guessing about it being a plural, try again but only
  1949. !  allowing singulars (so that words like "six" are not swallowed up as
  1950. !  Descriptors)
  1951.  
  1952.     if (allow_plurals && indef_guess_p==1)
  1953.     {   allow_plurals=false; wn=desc_wn; jump TryAgain;
  1954.     }
  1955.     return 0;
  1956. ];
  1957.  
  1958. ! ----------------------------------------------------------------------------
  1959. !  NounDomain does the most substantial part of parsing an object name.
  1960. !
  1961. !  It is given two "domains" - usually a location and then the actor who is
  1962. !  looking - and a context (i.e. token type), and returns:
  1963. !
  1964. !   0    if no match at all could be made,
  1965. !   1    if a multiple object was made,
  1966. !   k    if object k was the one decided upon,
  1967. !   REPARSE_CODE if it asked a question of the player and consequently rewrote
  1968. !        the player's input, so that the whole parser should start again
  1969. !        on the rewritten input.
  1970. !
  1971. !   In the case when it returns 1<k<REPARSE_CODE, it also sets the variable
  1972. !   length_of_noun to the number of words in the input text matched to the
  1973. !   noun.
  1974. !   In the case k=1, the multiple objects are added to multiple_object by
  1975. !   hand (not by MultiAdd, because we want to allow duplicates).
  1976. ! ----------------------------------------------------------------------------
  1977.  
  1978. [ NounDomain domain1 domain2 context    first_word i j k l
  1979.                                         answer_words marker;
  1980.  
  1981. #ifdef DEBUG;
  1982.   if (parser_trace>=4)
  1983.   {   print "   [NounDomain called at word ", wn, "^";
  1984.       print "   ";
  1985.       if (indef_mode)
  1986.       {   print "seeking indefinite object: ";
  1987.           if (indef_type & OTHER_BIT)  print "other ";
  1988.           if (indef_type & MY_BIT)     print "my ";
  1989.           if (indef_type & THAT_BIT)   print "that ";
  1990.           if (indef_type & PLURAL_BIT) print "plural ";
  1991.           if (indef_type & LIT_BIT)    print "lit ";
  1992.           if (indef_type & UNLIT_BIT)  print "unlit ";
  1993.           if (indef_owner ~= 0) print "owner:", (name) indef_owner;
  1994.           new_line;
  1995.           print "   number wanted: ";
  1996.           if (indef_wanted == 100) print "all"; else print indef_wanted;
  1997.           new_line;
  1998.           print "   most likely GNAs of names: ", indef_cases, "^";
  1999.       }
  2000.       else print "seeking definite object^";
  2001.   }
  2002. #endif;
  2003.  
  2004.   match_length=0; number_matched=0; match_from=wn; placed_in_flag=0;
  2005.  
  2006.   SearchScope(domain1, domain2, context);
  2007.  
  2008. #ifdef DEBUG;
  2009.   if (parser_trace>=4) print "   [ND made ", number_matched, " matches]^";
  2010. #endif;
  2011.  
  2012.   wn=match_from+match_length;
  2013.  
  2014. !  If nothing worked at all, leave with the word marker skipped past the
  2015. !  first unmatched word...
  2016.  
  2017.   if (number_matched==0) { wn++; rfalse; }
  2018.  
  2019. !  Suppose that there really were some words being parsed (i.e., we did
  2020. !  not just infer).  If so, and if there was only one match, it must be
  2021. !  right and we return it...
  2022.  
  2023.   if (match_from <= num_words)
  2024.   {   if (number_matched==1) { i=match_list-->0; return i; }
  2025.  
  2026. !  ...now suppose that there was more typing to come, i.e. suppose that
  2027. !  the user entered something beyond this noun.  If nothing ought to follow,
  2028. !  then there must be a mistake, (unless what does follow is just a full
  2029. !  stop, and or comma)
  2030.  
  2031.       if (wn<=num_words)
  2032.       {   i=NextWord(); wn--;
  2033.           if (i ~=  AND1__WD or AND2__WD or AND3__WD or comma_word
  2034.                  or THEN1__WD or THEN2__WD or THEN3__WD
  2035.                  or BUT1__WD or BUT2__WD or BUT3__WD)
  2036.           {   if (lookahead==ENDIT_TOKEN) rfalse;
  2037.           }
  2038.       }
  2039.   }
  2040.  
  2041. !  Now look for a good choice, if there's more than one choice...
  2042.  
  2043.   number_of_classes=0;
  2044.   
  2045.   if (number_matched==1) i=match_list-->0;
  2046.   if (number_matched>1)
  2047.   {   i=Adjudicate(context);
  2048.       if (i==-1) rfalse;
  2049.       if (i==1) rtrue;       !  Adjudicate has made a multiple
  2050.                              !  object, and we pass it on
  2051.   }
  2052.  
  2053. !  If i is non-zero here, one of two things is happening: either
  2054. !  (a) an inference has been successfully made that object i is
  2055. !      the intended one from the user's specification, or
  2056. !  (b) the user finished typing some time ago, but we've decided
  2057. !      on i because it's the only possible choice.
  2058. !  In either case we have to keep the pattern up to date,
  2059. !  note that an inference has been made and return.
  2060. !  (Except, we don't note which of a pile of identical objects.)
  2061.  
  2062.   if (i~=0)
  2063.   {   if (dont_infer) return i;
  2064.       if (inferfrom==0) inferfrom=pcount;
  2065.       pattern-->pcount = i;
  2066.       return i;
  2067.   }
  2068.  
  2069. !  If we get here, there was no obvious choice of object to make.  If in
  2070. !  fact we've already gone past the end of the player's typing (which
  2071. !  means the match list must contain every object in scope, regardless
  2072. !  of its name), then it's foolish to give an enormous list to choose
  2073. !  from - instead we go and ask a more suitable question...
  2074.  
  2075.   if (match_from > num_words) jump Incomplete;
  2076.  
  2077. !  Now we print up the question, using the equivalence classes as worked
  2078. !  out by Adjudicate() so as not to repeat ourselves on plural objects...
  2079.  
  2080.   if (context==CREATURE_TOKEN)
  2081.       L__M(##Miscellany, 45); else L__M(##Miscellany, 46);
  2082.  
  2083.   j=number_of_classes; marker=0;
  2084.   for (i=1:i<=number_of_classes:i++)
  2085.   {   
  2086.       while (((match_classes-->marker) ~= i)
  2087.              && ((match_classes-->marker) ~= -i)) marker++;
  2088.       k=match_list-->marker;
  2089.  
  2090.       if (match_classes-->marker > 0) print (the) k; else print (a) k;
  2091.  
  2092.       if (i<j-1)  print ", ";
  2093.       if (i==j-1) print (string) OR__TX;
  2094.   }
  2095.   print "?^";
  2096.  
  2097. !  ...and get an answer:
  2098.  
  2099.   .WhichOne;
  2100.   for (i=2:i<120:i++) buffer2->i=' ';
  2101.   answer_words=Keyboard(buffer2, parse2);
  2102.  
  2103.   first_word=(parse2-->1);
  2104.  
  2105. !  Take care of "all", because that does something too clever here to do
  2106. !  later on:
  2107.  
  2108.   if (first_word == ALL1__WD or ALL2__WD or ALL3__WD or ALL4__WD or ALL5__WD)
  2109.   {   
  2110.       if (context == MULTI_TOKEN or MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
  2111.                      or MULTIINSIDE_TOKEN)
  2112.       {   l=multiple_object-->0;
  2113.           for (i=0:i<number_matched && l+i<63:i++)
  2114.           {   k=match_list-->i;
  2115.               multiple_object-->(i+1+l) = k;
  2116.           }
  2117.           multiple_object-->0 = i+l;
  2118.           rtrue;
  2119.       }
  2120.       L__M(##Miscellany, 47);
  2121.       jump WhichOne;
  2122.   }
  2123.  
  2124. !  If the first word of the reply can be interpreted as a verb, then
  2125. !  assume that the player has ignored the question and given a new
  2126. !  command altogether.
  2127. !  (This is one time when it's convenient that the directions are
  2128. !  not themselves verbs - thus, "north" as a reply to "Which, the north
  2129. !  or south door" is not treated as a fresh command but as an answer.)
  2130.  
  2131.   #ifdef LanguageIsVerb;
  2132.   if (first_word==0)
  2133.   {   j = wn; first_word=LanguageIsVerb(buffer2, parse2, 1); wn = j;
  2134.   }
  2135.   #endif;
  2136.   if (first_word ~= 0)
  2137.   {   j=first_word->#dict_par1;
  2138.       if (0~=j&1)
  2139.       {   CopyBuffer(buffer, buffer2);
  2140.           return REPARSE_CODE;
  2141.       }
  2142.   }
  2143.  
  2144. !  Now we insert the answer into the original typed command, as
  2145. !  words additionally describing the same object
  2146. !  (eg, > take red button
  2147. !       Which one, ...
  2148. !       > music
  2149. !  becomes "take music red button".  The parser will thus have three
  2150. !  words to work from next time, not two.)
  2151.  
  2152.   k = WordAddress(match_from) - buffer; l=buffer2->1+1;
  2153.   for (j=buffer + buffer->0 - 1: j>= buffer+k+l: j--)
  2154.       j->0 = 0->(j-l);
  2155.   for (i=0:i<l:i++) buffer->(k+i) = buffer2->(2+i);
  2156.   buffer->(k+l-1) = ' ';
  2157.   buffer->1 = buffer->1 + l;
  2158.   if (buffer->1 >= (buffer->0 - 1)) buffer->1 = buffer->0;
  2159.  
  2160. !  Having reconstructed the input, we warn the parser accordingly
  2161. !  and get out.
  2162.  
  2163.   return REPARSE_CODE;
  2164.  
  2165. !  Now we come to the question asked when the input has run out
  2166. !  and can't easily be guessed (eg, the player typed "take" and there
  2167. !  were plenty of things which might have been meant).
  2168.  
  2169.   .Incomplete;
  2170.  
  2171.   if (context==CREATURE_TOKEN)
  2172.       L__M(##Miscellany, 48); else L__M(##Miscellany, 49);
  2173.  
  2174.   for (i=2:i<120:i++) buffer2->i=' ';
  2175.   answer_words=Keyboard(buffer2, parse2);
  2176.  
  2177.   first_word=(parse2-->1);
  2178.   #ifdef LanguageIsVerb;
  2179.   if (first_word==0)
  2180.   {   j = wn; first_word=LanguageIsVerb(buffer2, parse2, 1); wn = j;
  2181.   }
  2182.   #endif;
  2183.  
  2184. !  Once again, if the reply looks like a command, give it to the
  2185. !  parser to get on with and forget about the question...
  2186.  
  2187.   if (first_word ~= 0)
  2188.   {   j=first_word->#dict_par1;
  2189.       if (0~=j&1)
  2190.       {   CopyBuffer(buffer, buffer2);
  2191.           return REPARSE_CODE;
  2192.       }
  2193.   }
  2194.  
  2195. !  ...but if we have a genuine answer, then:
  2196. !
  2197. !  (1) we must glue in text suitable for anything that's been inferred.
  2198.  
  2199.   if (inferfrom ~= 0)
  2200.   {   for (j = inferfrom: j<pcount: j++)
  2201.       {   if (pattern-->j == PATTERN_NULL) continue;
  2202.           i=2+buffer->1; (buffer->1)++; buffer->(i++) = ' ';
  2203.     
  2204.           if (parser_trace >= 5)
  2205.           print "[Gluing in inference with pattern code ", pattern-->j, "]^";
  2206.  
  2207.           parse2-->1 = 0;
  2208.  
  2209.           ! An inferred object.  Best we can do is glue in a pronoun.
  2210.           ! (This is imperfect, but it's very seldom needed anyway.)
  2211.     
  2212.           if (pattern-->j >= 2 && pattern-->j < REPARSE_CODE)
  2213.           {   PronounNotice(pattern-->j);
  2214.               for (k=1: k<=LanguagePronouns-->0: k=k+3)
  2215.                   if (pattern-->j == LanguagePronouns-->(k+2))
  2216.                   {   parse2-->1 = LanguagePronouns-->k;
  2217.                       if (parser_trace >= 5)
  2218.                       print "[Using pronoun '", (address) parse2-->1, "']^";
  2219.                       break;
  2220.                   }
  2221.           }
  2222.           else
  2223.           {   ! An inferred preposition.
  2224.               parse2-->1 = No__Dword(pattern-->j - REPARSE_CODE);
  2225.               if (parser_trace >= 5)
  2226.                   print "[Using preposition '", (address) parse2-->1, "']^";
  2227.           }
  2228.     
  2229.           ! parse2-->1 now holds the dictionary address of the word to glue in.
  2230.     
  2231.           if (parse2-->1 ~= 0)
  2232.           {   k = buffer + i;
  2233.               @output_stream 3 k;
  2234.               print (address) parse2-->1;
  2235.               @output_stream -3;
  2236.               k = k-->0;
  2237.               for (l=i:l<i+k:l++) buffer->l = buffer->(l+2);
  2238.               i = i + k; buffer->1 = i-2;
  2239.           }
  2240.       }
  2241.   }
  2242.  
  2243. !  (2) we must glue the newly-typed text onto the end.
  2244.  
  2245.   i=2+buffer->1; (buffer->1)++; buffer->(i++) = ' ';
  2246.   for (j=0: j<buffer2->1: i++, j++)
  2247.   {   buffer->i = buffer2->(j+2);
  2248.       (buffer->1)++;
  2249.       if (buffer->1 == buffer->0) break;
  2250.   }    
  2251.  
  2252.   return REPARSE_CODE;
  2253. ];
  2254.  
  2255. ! ----------------------------------------------------------------------------
  2256. !  The Adjudicate routine tries to see if there is an obvious choice, when
  2257. !  faced with a list of objects (the match_list) each of which matches the
  2258. !  player's specification equally well.
  2259. !
  2260. !  To do this it makes use of the context (the token type being worked on).
  2261. !  It counts up the number of obvious choices for the given context
  2262. !  (all to do with where a candidate is, except for 6 (animate) which is to
  2263. !  do with whether it is animate or not);
  2264. !
  2265. !  if only one obvious choice is found, that is returned;
  2266. !
  2267. !  if we are in indefinite mode (don't care which) one of the obvious choices
  2268. !    is returned, or if there is no obvious choice then an unobvious one is
  2269. !    made;
  2270. !
  2271. !  at this stage, we work out whether the objects are distinguishable from
  2272. !    each other or not: if they are all indistinguishable from each other,
  2273. !    then choose one, it doesn't matter which;
  2274. !
  2275. !  otherwise, 0 (meaning, unable to decide) is returned (but remember that
  2276. !    the equivalence classes we've just worked out will be needed by other
  2277. !    routines to clear up this mess, so we can't economise on working them
  2278. !    out).
  2279. !
  2280. !  Returns -1 if an error occurred
  2281. ! ----------------------------------------------------------------------------
  2282.  
  2283. [ Adjudicate context i j k good_ones last n ultimate flag offset;
  2284.  
  2285. #ifdef DEBUG;
  2286.   if (parser_trace>=4)
  2287.   {   print "   [Adjudicating match list of size ", number_matched,
  2288.           " in context ", context, "^";
  2289.       print "   ";
  2290.       if (indef_mode)
  2291.       {   print "indefinite type: ";
  2292.           if (indef_type & OTHER_BIT)  print "other ";
  2293.           if (indef_type & MY_BIT)     print "my ";
  2294.           if (indef_type & THAT_BIT)   print "that ";
  2295.           if (indef_type & PLURAL_BIT) print "plural ";
  2296.           if (indef_type & LIT_BIT)    print "lit ";
  2297.           if (indef_type & UNLIT_BIT)  print "unlit ";
  2298.           if (indef_owner ~= 0) print "owner:", (name) indef_owner;
  2299.           new_line;
  2300.           print "   number wanted: ";
  2301.           if (indef_wanted == 100) print "all"; else print indef_wanted;
  2302.           new_line;
  2303.           print "   most likely GNAs of names: ", indef_cases, "^";
  2304.       }
  2305.       else print "definite object^";
  2306.   }
  2307. #endif;
  2308.  
  2309.   j=number_matched-1; good_ones=0; last=match_list-->0;
  2310.   for (i=0:i<=j:i++)
  2311.   {   n=match_list-->i;
  2312.       match_scores-->i = good_ones;
  2313.  
  2314.       ultimate=n;
  2315.       do
  2316.           ultimate=parent(ultimate);
  2317.       until (ultimate==actors_location or actor or 0);
  2318.  
  2319. !      if (context==NOUN_TOKEN && ultimate==actors_location
  2320. !          && n~=actor && n hasnt concealed && n hasnt scenery &&
  2321. !          (token_filter==0 || UserFilter(n)==1)) { good_ones++; last=n; }
  2322.       if (context==HELD_TOKEN && parent(n)==actor)
  2323.       {   good_ones++; last=n; }
  2324.       if (context==MULTI_TOKEN && ultimate==actors_location
  2325.           && n~=actor && n hasnt concealed && n hasnt scenery) 
  2326.       {   good_ones++; last=n; }
  2327.       if (context==MULTIHELD_TOKEN && parent(n)==actor)
  2328.       {   good_ones++; last=n; }
  2329.  
  2330.       if (context==MULTIEXCEPT_TOKEN or MULTIINSIDE_TOKEN)
  2331.       {   if (advance_warning==-1)
  2332.           {   if (context==MULTIEXCEPT_TOKEN)
  2333.               {   good_ones++; last=n;
  2334.               }
  2335.               if (context==MULTIINSIDE_TOKEN)
  2336.               {   if (parent(n)~=actor) { good_ones++; last=n; }
  2337.               }
  2338.           }
  2339.           else
  2340.           {   if (context==MULTIEXCEPT_TOKEN && n~=advance_warning)
  2341.               {   good_ones++; last=n; }
  2342.               if (context==MULTIINSIDE_TOKEN && n in advance_warning)
  2343.               {   good_ones++; last=n; }
  2344.           }
  2345.       }
  2346.       if (context==CREATURE_TOKEN && CreatureTest(n)==1)
  2347.       {   good_ones++; last=n; }
  2348.  
  2349.       match_scores-->i = 1000*(good_ones - match_scores-->i);
  2350.  
  2351.       #ifdef DEBUG;
  2352.       if (parser_trace>=4)
  2353.       {   print "   ML: ", (name) n, " ";
  2354.           print " initial score ", match_scores-->i, "^";
  2355.       }
  2356.       #endif;
  2357.   }
  2358.   if (good_ones==1) return last;
  2359.  
  2360.   ! If there is ambiguity about what was typed, but it definitely wasn't
  2361.   ! animate as required, then return anything; higher up in the parser
  2362.   ! a suitable error will be given.  (This prevents a question being asked.)
  2363.   !
  2364.   if (context==CREATURE_TOKEN && good_ones==0) return match_list-->0;
  2365.  
  2366.   if (indef_mode==0) indef_type=0;
  2367.  
  2368.   ScoreMatchL();
  2369.   if (number_matched == 0) return -1;
  2370.  
  2371.   if (indef_mode==1 && indef_type & PLURAL_BIT ~= 0)
  2372.   {   if (context ~= MULTI_TOKEN or MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
  2373.                      or MULTIINSIDE_TOKEN)
  2374.       {   etype=MULTI_PE; return -1; }
  2375.       i=0; offset=multiple_object-->0;
  2376.       for (j=BestGuess():j~=-1 && i<indef_wanted
  2377.            && i+offset<63:j=BestGuess())
  2378.       {   flag=0;
  2379.           if (j hasnt concealed && j hasnt worn) flag=1;
  2380.           if (context==MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
  2381.               && parent(j)~=actor) flag=0;
  2382.           k=ChooseObjects(j,flag);
  2383.           if (k==1) flag=1; else { if (k==2) flag=0; }
  2384.           if (flag==1)
  2385.           {   i++; multiple_object-->(i+offset) = j;
  2386. #ifdef DEBUG;
  2387.               if (parser_trace>=4) print "   Accepting it^";
  2388. #endif;
  2389.           }
  2390.           else
  2391.           {   i=i;
  2392. #ifdef DEBUG;
  2393.               if (parser_trace>=4) print "   Rejecting it^";
  2394. #endif;
  2395.           }
  2396.       }
  2397.       if (i<indef_wanted && indef_wanted<100)
  2398.       {   etype=TOOFEW_PE; multi_wanted=indef_wanted;
  2399.           multi_had=multiple_object-->0;
  2400.           return -1;
  2401.       }
  2402.       multiple_object-->0 = i+offset;
  2403.       multi_context=context;
  2404. #ifdef DEBUG;
  2405.       if (parser_trace>=4)
  2406.           print "   Made multiple object of size ", i, "]^";
  2407. #endif;
  2408.       return 1;
  2409.   }
  2410.  
  2411.   for (i=0:i<number_matched:i++) match_classes-->i=0;
  2412.  
  2413.   n=1;
  2414.   for (i=0:i<number_matched:i++)
  2415.       if (match_classes-->i==0)
  2416.       {   match_classes-->i=n++; flag=0;
  2417.           for (j=i+1:j<number_matched:j++)
  2418.               if (match_classes-->j==0
  2419.                   && Identical(match_list-->i, match_list-->j)==1)
  2420.               {   flag=1;
  2421.                   match_classes-->j=match_classes-->i;
  2422.               }
  2423.           if (flag==1) match_classes-->i = 1-n;
  2424.       }
  2425.   n--; number_of_classes = n;
  2426.  
  2427. #ifdef DEBUG;
  2428.   if (parser_trace>=4)
  2429.   {   print "   Difficult adjudication with ", n, " equivalence classes:^";
  2430.       for (i=0:i<number_matched:i++)
  2431.           print "   ", (The) match_list-->i,
  2432.                 " (", match_list-->i, ")  ---  ",match_classes-->i, "^";
  2433.   }
  2434. #endif;
  2435.  
  2436.   if (n>1 && indef_mode==0)
  2437.   {   j=0; good_ones=0;
  2438.       for (i=0:i<number_matched:i++)
  2439.       {   k=ChooseObjects(match_list-->i,2);
  2440.           if (k==j) good_ones++;
  2441.           if (k>j) { j=k; good_ones=1; last=match_list-->i; }
  2442.       }
  2443.       if (good_ones==1)
  2444.       {
  2445. #ifdef DEBUG;
  2446.           if (parser_trace>=4)
  2447.               print "   ChooseObjects picked a best.]^";
  2448. #endif;
  2449.           return last;
  2450.       }
  2451. #ifdef DEBUG;
  2452.       if (parser_trace>=4)
  2453.           print "   Unable to decide: it's a draw.]^";
  2454. #endif;
  2455.       return 0;
  2456.   }
  2457.  
  2458. !  When the player is really vague, or there's a single collection of
  2459. !  indistinguishable objects to choose from, choose the one the player
  2460. !  most recently acquired, or if the player has none of them, then
  2461. !  the one most recently put where it is.
  2462.  
  2463.   if (n==1) dont_infer = true;
  2464.   return BestGuess();
  2465. ];
  2466.  
  2467. ! ----------------------------------------------------------------------------
  2468. !  ReviseMulti  revises the multiple object which already exists, in the
  2469. !    light of information which has come along since then (i.e., the second
  2470. !    parameter).  It returns a parser error number, or else 0 if all is well.
  2471. !    This only ever throws things out, never adds new ones.
  2472. ! ----------------------------------------------------------------------------
  2473.  
  2474. [ ReviseMulti second_p  i low;
  2475.  
  2476. #ifdef DEBUG;
  2477.   if (parser_trace>=4)
  2478.       print "   Revising multiple object list of size ", multiple_object-->0,
  2479.             " with 2nd ", (name) second_p, "^";
  2480. #endif;
  2481.  
  2482.   if (multi_context==MULTIEXCEPT_TOKEN or MULTIINSIDE_TOKEN)
  2483.   {   for (i=1, low=0:i<=multiple_object-->0:i++)
  2484.       {   if ( (multi_context==MULTIEXCEPT_TOKEN
  2485.                 && multiple_object-->i ~= second_p)
  2486.                || (multi_context==MULTIINSIDE_TOKEN
  2487.                    && multiple_object-->i in second_p))
  2488.           {   low++; multiple_object-->low = multiple_object-->i;
  2489.           }
  2490.       }
  2491.       multiple_object-->0 = low;
  2492.   }
  2493.  
  2494.   if (multi_context==MULTI_TOKEN && action_to_be == ##Take)
  2495.   {   for (i=1, low=0:i<=multiple_object-->0:i++)
  2496.           if (parent(multiple_object-->i)==parent(actor)) low++;
  2497. #ifdef DEBUG;
  2498.       if (parser_trace>=4)
  2499.           print "   Token 2 plural case: number with actor ", low, "^";
  2500. #endif;
  2501.       if (take_all_rule==2 || low>0)
  2502.       {   for (i=1, low=0:i<=multiple_object-->0:i++)
  2503.           {   if (parent(multiple_object-->i)==parent(actor))
  2504.               {   low++; multiple_object-->low = multiple_object-->i;
  2505.               }
  2506.           }
  2507.           multiple_object-->0 = low;
  2508.       }
  2509.   }
  2510.  
  2511.   i=multiple_object-->0;
  2512. #ifdef DEBUG;
  2513.   if (parser_trace>=4)
  2514.       print "   Done: new size ", i, "^";
  2515. #endif;
  2516.   if (i==0) return NOTHING_PE;
  2517.   return 0;
  2518. ];
  2519.  
  2520. ! ----------------------------------------------------------------------------
  2521. !  ScoreMatchL  scores the match list for quality in terms of what the
  2522. !  player has vaguely asked for.  Points are awarded for conforming with
  2523. !  requirements like "my", and so on.  Remove from the match list any
  2524. !  entries which fail the basic requirements of the descriptors.
  2525. ! ----------------------------------------------------------------------------
  2526.  
  2527. [ ScoreMatchL  its_owner its_score obj i j threshold a_s l_s;
  2528.  
  2529. !  if (indef_type & OTHER_BIT ~= 0) threshold=45;
  2530.   if (indef_type & MY_BIT ~= 0)    threshold=threshold+45;
  2531.   if (indef_type & THAT_BIT ~= 0)  threshold=threshold+45;
  2532.   if (indef_type & LIT_BIT ~= 0)   threshold=threshold+45;
  2533.   if (indef_type & UNLIT_BIT ~= 0) threshold=threshold+45;
  2534.   if (indef_owner ~= nothing)      threshold=threshold+45;
  2535.  
  2536. #ifdef DEBUG;
  2537.   if (parser_trace>=4) print "   Scoring match list: indef mode ", indef_mode,
  2538.       " type ", indef_type,
  2539.       ", threshold ", threshold, ":^";
  2540. #endif;
  2541.  
  2542.   a_s = 30; l_s = 20;
  2543.   if (action_to_be == ##Take or ##Remove) { a_s=20; l_s=30; }
  2544.  
  2545.   for (i=0:i<number_matched:i++)
  2546.   {   obj = match_list-->i; its_owner = parent(obj); its_score=0;
  2547.  
  2548. !      if (indef_type & OTHER_BIT ~=0
  2549. !          &&  obj~=itobj or himobj or herobj)
  2550. !          its_score=its_score+45;
  2551.       if (indef_type & MY_BIT ~=0  &&  its_owner==actor)
  2552.           its_score=its_score+45;
  2553.       if (indef_type & THAT_BIT ~=0  &&  its_owner==actors_location)
  2554.           its_score=its_score+45;
  2555.       if (indef_type & LIT_BIT ~=0  &&  obj has light)
  2556.           its_score=its_score+45;
  2557.       if (indef_type & UNLIT_BIT ~=0  &&  obj hasnt light)
  2558.           its_score=its_score+45;
  2559.       if (indef_owner~=0 && its_owner == indef_owner)
  2560.           its_score=its_score+45;
  2561.  
  2562.       if (its_score < threshold)
  2563.       {
  2564. #ifdef DEBUG;
  2565.           if (parser_trace >= 4)
  2566.               print "   ", (The) match_list-->i,
  2567.                     " (", match_list-->i, ") in ", (the) its_owner,
  2568.                     " is rejected (doesn't match descriptors)^";
  2569. #endif;
  2570.           match_list-->i=-1;
  2571.       }
  2572.       else
  2573.       {   !   Now forget all of that: the object passes descriptors
  2574.           !   and we can score it properly.
  2575.  
  2576.           its_score = 0;
  2577.           if (obj hasnt concealed) its_score=50;
  2578.  
  2579.           if (its_owner==actor)   its_score = its_score+a_s;
  2580.           else
  2581.           if (its_owner==actors_location) its_score = its_score+l_s;
  2582.           else
  2583.           if (its_score==0 && its_owner~=compass) its_score = its_score+10;
  2584.  
  2585.           !   The entry point "ChooseObjects" can contribute 0 to 9 points
  2586.           !   to refine the score
  2587.           its_score = its_score + ChooseObjects(obj,2);
  2588.  
  2589.           !   A small bonus for having the correct GNA,
  2590.           !   for sorting out ambiguous articles and the like.
  2591.  
  2592.           its_score = 2*its_score;
  2593.           if (indef_cases & (PowersOfTwo_TB-->(GetGNAOfObject(obj))))
  2594.               its_score++;
  2595.  
  2596.           match_scores-->i = match_scores-->i + its_score;
  2597. #ifdef DEBUG;
  2598.           if (parser_trace >= 4)
  2599.               print "   ", (The) match_list-->i,
  2600.                     " (", match_list-->i, ") in ", (the) its_owner,
  2601.                     " scores ", match_scores-->i, "^";
  2602. #endif;
  2603.       }
  2604.   }
  2605.  
  2606.   for (i=0:i<number_matched:i++)
  2607.   {   while (match_list-->i == -1)
  2608.       {   if (i == number_matched-1) { number_matched--; break; }
  2609.           for (j=i:j<number_matched:j++)
  2610.               match_list-->j = match_list-->(j+1);
  2611.           number_matched--;
  2612.       }
  2613.   }
  2614. ];
  2615.  
  2616. ! ----------------------------------------------------------------------------
  2617. !  BestGuess makes the best guess it can out of the match list, assuming that
  2618. !  everything in the match list is textually as good as everything else;
  2619. !  however it ignores items marked as -1, and so marks anything it chooses.
  2620. !  It returns -1 if there are no possible choices.
  2621. ! ----------------------------------------------------------------------------
  2622.  
  2623. [ BestGuess  earliest its_score best i;
  2624.  
  2625.   earliest=0; best=-1;
  2626.   for (i=0:i<number_matched:i++)
  2627.   {   if (match_list-->i >= 0)
  2628.       {   its_score=match_scores-->i;
  2629.           if (its_score>best) { best=its_score; earliest=i; }
  2630.       }
  2631.   }
  2632. #ifdef DEBUG;
  2633.   if (parser_trace>=4)
  2634.   {   if (best<0)
  2635.           print "   Best guess ran out of choices^";
  2636.       else
  2637.           print "   Best guess ", (the) match_list-->earliest,
  2638.                 " (", match_list-->earliest, ")^";
  2639.   }
  2640. #endif;
  2641.   if (best<0) return -1;
  2642.   i=match_list-->earliest;
  2643.   match_list-->earliest=-1;
  2644.   return i;
  2645. ];
  2646.  
  2647. ! ----------------------------------------------------------------------------
  2648. !  Identical decides whether or not two objects can be distinguished from
  2649. !  each other by anything the player can type.  If not, it returns true.
  2650. ! ----------------------------------------------------------------------------
  2651.  
  2652. [ Identical o1 o2 p1 p2 n1 n2 i j flag;
  2653.  
  2654.   if (o1==o2) rtrue;  ! This should never happen, but to be on the safe side
  2655.   if (o1==0 || o2==0) rfalse;  ! Similarly
  2656.   if (parent(o1)==compass || parent(o2)==compass) rfalse; ! Saves time
  2657.  
  2658. !  What complicates things is that o1 or o2 might have a parsing routine,
  2659. !  so the parser can't know from here whether they are or aren't the same.
  2660. !  If they have different parsing routines, we simply assume they're
  2661. !  different.  If they have the same routine (which they probably got from
  2662. !  a class definition) then the decision process is as follows:
  2663. !
  2664. !     the routine is called (with self being o1, not that it matters)
  2665. !       with noun and second being set to o1 and o2, and action being set
  2666. !       to the fake action TheSame.  If it returns -1, they are found
  2667. !       identical; if -2, different; and if >=0, then the usual method
  2668. !       is used instead.
  2669.  
  2670.   if (o1.parse_name~=0 || o2.parse_name~=0)
  2671.   {   if (o1.parse_name ~= o2.parse_name) rfalse;
  2672.       parser_action=##TheSame; parser_one=o1; parser_two=o2;
  2673.       j=wn; i=RunRoutines(o1,parse_name); wn=j;
  2674.       if (i==-1) rtrue; if (i==-2) rfalse;
  2675.   }
  2676.  
  2677. !  This is the default algorithm: do they have the same words in their
  2678. !  "name" (i.e. property no. 1) properties.  (Note that the following allows
  2679. !  for repeated words and words in different orders.)
  2680.  
  2681.   p1 = o1.&1; n1 = (o1.#1)/2;
  2682.   p2 = o2.&1; n2 = (o2.#1)/2;
  2683.  
  2684. !  for (i=0:i<n1:i++) { print (address) p1-->i, " "; } new_line;
  2685. !  for (i=0:i<n2:i++) { print (address) p2-->i, " "; } new_line;
  2686.  
  2687.   for (i=0:i<n1:i++)
  2688.   {   flag=0;
  2689.       for (j=0:j<n2:j++)
  2690.           if (p1-->i == p2-->j) flag=1;
  2691.       if (flag==0) rfalse;
  2692.   }
  2693.  
  2694.   for (j=0:j<n2:j++)
  2695.   {   flag=0;
  2696.       for (i=0:i<n1:i++)
  2697.           if (p1-->i == p2-->j) flag=1;
  2698.       if (flag==0) rfalse;
  2699.   }
  2700.  
  2701. !  print "Which are identical!^";
  2702.   rtrue;
  2703. ];
  2704.  
  2705. ! ----------------------------------------------------------------------------
  2706. !  PrintCommand reconstructs the command as it presently reads, from
  2707. !  the pattern which has been built up
  2708. !
  2709. !  If from is 0, it starts with the verb: then it goes through the pattern.
  2710. !  The other parameter is "emptyf" - a flag: if 0, it goes up to pcount:
  2711. !  if 1, it goes up to pcount-1.
  2712. !
  2713. !  Note that verbs and prepositions are printed out of the dictionary:
  2714. !  and that since the dictionary may only preserve the first six characters
  2715. !  of a word (in a V3 game), we have to hand-code the longer words needed.
  2716. !
  2717. !  (Recall that pattern entries are 0 for "multiple object", 1 for "special
  2718. !  word", 2 to REPARSE_CODE-1 are object numbers and REPARSE_CODE+n means the
  2719. !  preposition n)
  2720. ! ----------------------------------------------------------------------------
  2721.  
  2722. [ PrintCommand from i k spacing_flag;
  2723.  
  2724.   if (from==0)
  2725.   {   i=verb_word;
  2726.       if (LanguageVerb(i) == 0)
  2727.           if (PrintVerb(i) == 0)
  2728.               print (address) i;
  2729.       from++; spacing_flag = true;
  2730.   }
  2731.  
  2732.   for (k=from:k<pcount:k++)
  2733.   {   i=pattern-->k;
  2734.       if (i == PATTERN_NULL) continue;
  2735.       if (spacing_flag) print (char) ' ';
  2736.       if (i==0) { print (string) THOSET__TX; jump TokenPrinted; }
  2737.       if (i==1) { print (string) THAT__TX; jump TokenPrinted; }
  2738.       if (i>=REPARSE_CODE) print (address) No__Dword(i-REPARSE_CODE);
  2739.       else print (the) i;
  2740.       .TokenPrinted;
  2741.       spacing_flag = true;
  2742.   }
  2743. ];
  2744.  
  2745. ! ----------------------------------------------------------------------------
  2746. !  The CantSee routine returns a good error number for the situation where
  2747. !  the last word looked at didn't seem to refer to any object in context.
  2748. !
  2749. !  The idea is that: if the actor is in a location (but not inside something
  2750. !  like, for instance, a tank which is in that location) then an attempt to
  2751. !  refer to one of the words listed as meaningful-but-irrelevant there
  2752. !  will cause "you don't need to refer to that in this game" rather than
  2753. !  "no such thing" or "what's 'it'?".
  2754. !  (The advantage of not having looked at "irrelevant" local nouns until now
  2755. !  is that it stops them from clogging up the ambiguity-resolving process.
  2756. !  Thus game objects always triumph over scenery.)
  2757. ! ----------------------------------------------------------------------------
  2758.  
  2759. [ CantSee  i w e;
  2760.     saved_oops=oops_from;
  2761.  
  2762.     if (scope_token~=0) { scope_error = scope_token; return ASKSCOPE_PE; }
  2763.  
  2764.     wn--; w=NextWord();
  2765.     e=CANTSEE_PE;
  2766.     if (w==pronoun_word)
  2767.     {   pronoun__word=pronoun_word; pronoun__obj=pronoun_obj;
  2768.         e=ITGONE_PE;
  2769.     }
  2770.     i=actor; while (parent(i) ~= 0) i = parent(i);
  2771.     if (i has visited && Refers(i,wn-1)==1) e=SCENERY_PE;
  2772.     if (etype>e) return etype;
  2773.     return e;
  2774. ];
  2775.  
  2776. ! ----------------------------------------------------------------------------
  2777. !  The MultiAdd routine adds object "o" to the multiple-object-list.
  2778. !
  2779. !  This is only allowed to hold 63 objects at most, at which point it ignores
  2780. !  any new entries (and sets a global flag so that a warning may later be
  2781. !  printed if need be).
  2782. ! ----------------------------------------------------------------------------
  2783.  
  2784. [ MultiAdd o i j;
  2785.   i=multiple_object-->0;
  2786.   if (i==63) { toomany_flag=1; rtrue; }
  2787.   for (j=1:j<=i:j++)
  2788.       if (o==multiple_object-->j) 
  2789.           rtrue;
  2790.   i++;
  2791.   multiple_object-->i = o;
  2792.   multiple_object-->0 = i;
  2793. ];
  2794.  
  2795. ! ----------------------------------------------------------------------------
  2796. !  The MultiSub routine deletes object "o" from the multiple-object-list.
  2797. !
  2798. !  It returns 0 if the object was there in the first place, and 9 (because
  2799. !  this is the appropriate error number in Parser()) if it wasn't.
  2800. ! ----------------------------------------------------------------------------
  2801.  
  2802. [ MultiSub o i j k et;
  2803.   i=multiple_object-->0; et=0;
  2804.   for (j=1:j<=i:j++)
  2805.       if (o==multiple_object-->j)
  2806.       {   for (k=j:k<=i:k++)
  2807.               multiple_object-->k = multiple_object-->(k+1);
  2808.           multiple_object-->0 = --i;
  2809.           return et;
  2810.       }
  2811.   et=9; return et;
  2812. ];
  2813.  
  2814. ! ----------------------------------------------------------------------------
  2815. !  The MultiFilter routine goes through the multiple-object-list and throws
  2816. !  out anything without the given attribute "attr" set.
  2817. ! ----------------------------------------------------------------------------
  2818.  
  2819. [ MultiFilter attr  i j o;
  2820.   .MFiltl;
  2821.   i=multiple_object-->0;
  2822.   for (j=1:j<=i:j++)
  2823.   {   o=multiple_object-->j;
  2824.       if (o hasnt attr) { MultiSub(o); jump Mfiltl; }
  2825.   }
  2826. ];
  2827.  
  2828. ! ----------------------------------------------------------------------------
  2829. !  The UserFilter routine consults the user's filter (or checks on attribute)
  2830. !  to see what already-accepted nouns are acceptable
  2831. ! ----------------------------------------------------------------------------
  2832.  
  2833. [ UserFilter obj;
  2834.  
  2835.   if (token_filter > 0 && token_filter < 49)
  2836.   {   if (obj has (token_filter-1)) rtrue;
  2837.       rfalse;
  2838.   }
  2839.   noun = obj;
  2840.   return indirect(token_filter);
  2841. ];
  2842.  
  2843. ! ----------------------------------------------------------------------------
  2844. !  MoveWord copies word at2 from parse buffer b2 to word at1 in "parse"
  2845. !  (the main parse buffer)
  2846. ! ----------------------------------------------------------------------------
  2847.  
  2848. [ MoveWord at1 b2 at2 x y;
  2849.   x=at1*2-1; y=at2*2-1;
  2850.   parse-->x++ = b2-->y++;
  2851.   parse-->x = b2-->y;
  2852. ];
  2853.  
  2854. ! ----------------------------------------------------------------------------
  2855. !  SearchScope  domain1 domain2 context
  2856. !
  2857. !  Works out what objects are in scope (possibly asking an outside routine),
  2858. !  but does not look at anything the player has typed.
  2859. ! ----------------------------------------------------------------------------
  2860.  
  2861. [ SearchScope domain1 domain2 context i;
  2862.  
  2863.   i=0;
  2864. !  Everything is in scope to the debugging commands
  2865.  
  2866. #ifdef DEBUG;
  2867.   if (scope_reason==PARSING_REASON
  2868.       && verb_word == 'purloin' or 'tree' or 'abstract'
  2869.                        or 'gonear' or 'scope' or 'showobj')
  2870.   {   for (i=selfobj:i<=top_object:i++) PlaceInScope(i);
  2871.       rtrue;
  2872.   }
  2873. #endif;
  2874.  
  2875. !  First, a scope token gets priority here:
  2876.  
  2877.   if (scope_token ~= 0)
  2878.   {   scope_stage=2;
  2879.       if (indirect(scope_token)~=0) rtrue;
  2880.   }
  2881.  
  2882. !  Next, call any user-supplied routine adding things to the scope,
  2883. !  which may circumvent the usual routines altogether if they return true:
  2884.  
  2885.   if (actor==domain1 or domain2 && InScope(actor)~=0) rtrue;
  2886.  
  2887. !  Pick up everything in the location except the actor's possessions;
  2888. !  then go through those.  (This ensures the actor's possessions are in
  2889. !  scope even in Darkness.)
  2890.  
  2891.   if (context==MULTIINSIDE_TOKEN && advance_warning ~= -1)
  2892.   {   if (IsSeeThrough(advance_warning)==1)
  2893.           ScopeWithin(advance_warning, 0, context);
  2894.   }
  2895.   else
  2896.   {   if (domain1~=0 && domain1 has supporter or container)
  2897.           ScopeWithin_O(domain1, domain1, context);
  2898.       ScopeWithin(domain1, domain2, context);
  2899.       if (domain2~=0 && domain2 has supporter or container)
  2900.           ScopeWithin_O(domain2, domain2, context);
  2901.       ScopeWithin(domain2, 0, context);
  2902.   }
  2903.  
  2904. !  A special rule applies:
  2905. !  in Darkness as in light, the actor is always in scope to himself.
  2906.  
  2907.   if (thedark == domain1 or domain2)
  2908.   {   ScopeWithin_O(actor, actor, context);
  2909.       if (parent(actor) has supporter or container)
  2910.           ScopeWithin_O(parent(actor), parent(actor), context);
  2911.   }
  2912. ];
  2913.  
  2914. ! ----------------------------------------------------------------------------
  2915. !  IsSeeThrough is used at various places: roughly speaking, it determines
  2916. !  whether o being in scope means that the contents of o are in scope.
  2917. ! ----------------------------------------------------------------------------
  2918.  
  2919. [ IsSeeThrough o;
  2920.   if (o has supporter
  2921.       || (o has transparent)
  2922.       || (o has container && o has open))
  2923.       rtrue;
  2924.   rfalse;
  2925. ];
  2926.  
  2927. ! ----------------------------------------------------------------------------
  2928. !  PlaceInScope is provided for routines outside the library, and is not
  2929. !  called within the parser (except for debugging purposes).
  2930. ! ----------------------------------------------------------------------------
  2931.  
  2932. [ PlaceInScope thing;
  2933.    if (scope_reason~=PARSING_REASON or TALKING_REASON)
  2934.    {   DoScopeAction(thing); rtrue; }
  2935.    wn=match_from; TryGivenObject(thing); placed_in_flag=1;
  2936. ];
  2937.  
  2938. ! ----------------------------------------------------------------------------
  2939. !  DoScopeAction
  2940. ! ----------------------------------------------------------------------------
  2941.  
  2942. [ DoScopeAction thing s p1;
  2943.   s = scope_reason; p1=parser_one;
  2944. #ifdef DEBUG;
  2945.   if (parser_trace>=6)
  2946.   {   print "[DSA on ", (the) thing, " with reason = ", scope_reason,
  2947.       " p1 = ", parser_one, " p2 = ", parser_two, "]^";
  2948.   }
  2949. #endif;
  2950.   switch(scope_reason)
  2951.   {   REACT_BEFORE_REASON:
  2952.           if (thing.react_before==0 or NULL) return;
  2953. #ifdef DEBUG;
  2954.           if (parser_trace>=2)
  2955.           {   print "[Considering react_before for ", (the) thing, "]^"; }
  2956. #endif;
  2957.           if (parser_one==0) parser_one = RunRoutines(thing,react_before);
  2958.       REACT_AFTER_REASON:
  2959.           if (thing.react_after==0 or NULL) return;
  2960. #ifdef DEBUG;
  2961.           if (parser_trace>=2)
  2962.           {   print "[Considering react_after for ", (the) thing, "]^"; }
  2963. #endif;
  2964.           if (parser_one==0) parser_one = RunRoutines(thing,react_after);
  2965.       EACH_TURN_REASON:
  2966.           if (thing.&each_turn==0) return;
  2967. #ifdef DEBUG;
  2968.           if (parser_trace>=2)
  2969.           {   print "[Considering each_turn for ", (the) thing, "]^"; }
  2970. #endif;
  2971.           PrintOrRun(thing, each_turn);
  2972.       TESTSCOPE_REASON:
  2973.           if (thing==parser_one) parser_two = 1;
  2974.       LOOPOVERSCOPE_REASON:
  2975.           indirect(parser_one,thing); parser_one=p1;
  2976.   }
  2977.   scope_reason = s;
  2978. ];
  2979.  
  2980. ! ----------------------------------------------------------------------------
  2981. !  ScopeWithin looks for objects in the domain which make textual sense
  2982. !  and puts them in the match list.  (However, it does not recurse through
  2983. !  the second argument.)
  2984. ! ----------------------------------------------------------------------------
  2985.  
  2986. [ ScopeWithin domain nosearch context;
  2987.  
  2988.    if (domain==0) rtrue;
  2989.  
  2990. !  Special rule: the directions (interpreted as the 12 walls of a room) are
  2991. !  always in context.  (So, e.g., "examine north wall" is always legal.)
  2992. !  (Unless we're parsing something like "all", because it would just slow
  2993. !  things down then, or unless the context is "creature".)
  2994.  
  2995.    if (indef_mode==0 && domain==actors_location
  2996.        && scope_reason==PARSING_REASON && context~=CREATURE_TOKEN)
  2997.            ScopeWithin(compass);
  2998.  
  2999. !  Look through the objects in the domain
  3000.    objectloop (domain in domain) ScopeWithin_O(domain, nosearch, context);
  3001. ];
  3002.  
  3003. [ ScopeWithin_O domain nosearch context i ad n;
  3004.  
  3005. !  multiexcept doesn't have second parameter in scope
  3006.    if (context==MULTIEXCEPT_TOKEN && domain==advance_warning) jump DontAccept;
  3007.  
  3008. !  If the scope reason is unusual, don't parse.
  3009.  
  3010.       if (scope_reason~=PARSING_REASON or TALKING_REASON)
  3011.       {   DoScopeAction(domain); jump DontAccept; }
  3012.  
  3013. !  "it" or "them" matches to the it-object only.  (Note that (1) this means
  3014. !  that "it" will only be understood if the object in question is still
  3015. !  in context, and (2) only one match can ever be made in this case.)
  3016.  
  3017.       if (match_from <= num_words)  ! If there's any text to match, that is
  3018.       {   wn=match_from;
  3019.           i=NounWord();
  3020.           if (i==1 && player==domain)  MakeMatch(domain, 1);
  3021.  
  3022.           if (i>=2 && i<128 && (LanguagePronouns-->i == domain))
  3023.               MakeMatch(domain, 1);
  3024.       }
  3025.  
  3026. !  Construing the current word as the start of a noun, can it refer to the
  3027. !  object?
  3028.  
  3029.       wn = match_from;
  3030.       if (TryGivenObject(domain) > 0)
  3031.           if (indef_nspec_at>0 && match_from~=indef_nspec_at)
  3032.           {   !  This case arises if the player has typed a number in
  3033.               !  which is hypothetically an indefinite descriptor:
  3034.               !  e.g. "take two clubs".  We have just checked the object
  3035.               !  against the word "clubs", in the hope of eventually finding
  3036.               !  two such objects.  But we also backtrack and check it
  3037.               !  against the words "two clubs", in case it turns out to
  3038.               !  be the 2 of Clubs from a pack of cards, say.  If it does
  3039.               !  match against "two clubs", we tear up our original
  3040.               !  assumption about the meaning of "two" and lapse back into
  3041.               !  definite mode.
  3042.           
  3043.               wn = indef_nspec_at;
  3044.               if (TryGivenObject(domain) > 0)
  3045.               {   match_from = indef_nspec_at;
  3046.                   ResetDescriptors();                  
  3047.               }
  3048.               wn = match_from;
  3049.           }
  3050.  
  3051.       .DontAccept;
  3052.  
  3053. !  Shall we consider the possessions of the current object, as well?
  3054. !  Only if it's a container (so, for instance, if a dwarf carries a
  3055. !  sword, then "drop sword" will not be accepted, but "dwarf, drop sword"
  3056. !  will).
  3057. !  Also, only if there are such possessions.
  3058. !
  3059. !  Notice that the parser can see "into" anything flagged as
  3060. !  transparent - such as a dwarf whose sword you can get at.
  3061.  
  3062.       if (child(domain)~=0 && domain ~= nosearch && IsSeeThrough(domain)==1)
  3063.           ScopeWithin(domain,nosearch,context);
  3064.  
  3065. !  Drag any extras into context
  3066.  
  3067.    ad = domain.&add_to_scope;
  3068.    if (ad ~= 0)
  3069.    {   if (UnsignedCompare(ad-->0,top_object) > 0)
  3070.        {   ats_flag = 2+context;
  3071.            RunRoutines(domain, add_to_scope);
  3072.            ats_flag = 0;
  3073.        }
  3074.        else
  3075.        {   n=domain.#add_to_scope;
  3076.            for (i=0:(2*i)<n:i++)
  3077.                ScopeWithin_O(ad-->i,0,context);
  3078.        }
  3079.    }
  3080. ];
  3081.  
  3082. [ AddToScope obj;
  3083.    if (ats_flag>=2)
  3084.        ScopeWithin_O(obj,0,ats_flag-2);
  3085.    if (ats_flag==1)
  3086.    {   if  (HasLightSource(obj)==1) ats_hls = 1;
  3087.    }
  3088. ];
  3089.  
  3090. ! ----------------------------------------------------------------------------
  3091. !  MakeMatch looks at how good a match is.  If it's the best so far, then
  3092. !  wipe out all the previous matches and start a new list with this one.
  3093. !  If it's only as good as the best so far, add it to the list.
  3094. !  If it's worse, ignore it altogether.
  3095. !
  3096. !  The idea is that "red panic button" is better than "red button" or "panic".
  3097. !
  3098. !  number_matched (the number of words matched) is set to the current level
  3099. !  of quality.
  3100. !
  3101. !  We never match anything twice, and keep at most 64 equally good items.
  3102. ! ----------------------------------------------------------------------------
  3103.  
  3104. [ MakeMatch obj quality i;
  3105. #ifdef DEBUG;
  3106.    if (parser_trace>=6) print "    Match with quality ",quality,"^";
  3107. #endif;
  3108.    if (token_filter~=0 && UserFilter(obj)==0)
  3109.    {   #ifdef DEBUG;
  3110.        if (parser_trace>=6)
  3111.        {   print "    Match filtered out: token filter ", token_filter, "^";
  3112.        }
  3113.        #endif;
  3114.        rtrue;
  3115.    }
  3116.    if (quality < match_length) rtrue;
  3117.    if (quality > match_length) { match_length=quality; number_matched=0; }
  3118.    else
  3119.    {   if (2*number_matched>=MATCH_LIST_SIZE) rtrue;
  3120.        for (i=0:i<number_matched:i++)
  3121.            if (match_list-->i==obj) rtrue;
  3122.    }
  3123.    match_list-->number_matched++ = obj;
  3124. #ifdef DEBUG;
  3125.    if (parser_trace>=6) print "    Match added to list^";
  3126. #endif;
  3127. ];
  3128.  
  3129. ! ----------------------------------------------------------------------------
  3130. !  TryGivenObject tries to match as many words as possible in what has been
  3131. !  typed to the given object, obj.  If it manages any words matched at all,
  3132. !  it calls MakeMatch to say so, then returns the number of words (or 1
  3133. !  if it was a match because of inadequate input).
  3134. ! ----------------------------------------------------------------------------
  3135.  
  3136. [ TryGivenObject obj threshold k w j;
  3137.  
  3138. #ifdef DEBUG;
  3139.    if (parser_trace>=5)
  3140.        print "    Trying ", (the) obj, " (", obj, ") at word ", wn, "^";
  3141. #endif;
  3142.  
  3143.    dict_flags_of_noun = 0;
  3144.  
  3145. !  If input has run out then always match, with only quality 0 (this saves
  3146. !  time).
  3147.  
  3148.    if (wn > num_words)
  3149.    {   if (indef_mode ~= 0)
  3150.            dict_flags_of_noun = $$01110000;  ! Reject "plural" bit
  3151.        MakeMatch(obj,0);
  3152.        #ifdef DEBUG;
  3153.        if (parser_trace>=5)
  3154.        print "    Matched (0)^";
  3155.        #endif;
  3156.        return 1;
  3157.    }
  3158.  
  3159. !  Ask the object to parse itself if necessary, sitting up and taking notice
  3160. !  if it says the plural was used:
  3161.  
  3162.    if (obj.parse_name~=0)
  3163.    {   parser_action = NULL; j=wn;
  3164.        k=RunRoutines(obj,parse_name);
  3165.        if (k>0)
  3166.        {   wn=j+k;
  3167.            .MMbyPN;
  3168.  
  3169.            if (parser_action == ##PluralFound)
  3170.                dict_flags_of_noun = dict_flags_of_noun | 4;
  3171.  
  3172.            if (dict_flags_of_noun & 4)
  3173.            {   if (~~allow_plurals) k=0;
  3174.                else
  3175.                {   if (indef_mode==0)
  3176.                    {   indef_mode=1; indef_type=0; indef_wanted=0; }
  3177.                    indef_type = indef_type | PLURAL_BIT;
  3178.                    if (indef_wanted==0) indef_wanted=100;
  3179.                }
  3180.            }
  3181.  
  3182.            #ifdef DEBUG;
  3183.                if (parser_trace>=5)
  3184.                {   print "    Matched (", k, ")^";
  3185.                }
  3186.            #endif;
  3187.            MakeMatch(obj,k);
  3188.            return k;
  3189.        }
  3190.        if (k==0) jump NoWordsMatch;
  3191.    }
  3192.  
  3193. !  The default algorithm is simply to count up how many words pass the
  3194. !  Refers test:
  3195.  
  3196.    parser_action = NULL;
  3197.  
  3198.    w = NounWord();
  3199.  
  3200.    if (w==1 && player==obj) { k=1; jump MMbyPN; }
  3201.  
  3202.    if (w>=2 && w<128 && (LanguagePronouns-->w == obj))
  3203.    {   k=1; jump MMbyPN; }
  3204.  
  3205.    j=--wn;
  3206.    threshold = ParseNoun(obj);
  3207. #ifdef DEBUG;
  3208.    if (threshold>=0 && parser_trace>=5)
  3209.        print "    ParseNoun returned ", threshold, "^";
  3210. #endif;
  3211.    if (threshold<0) wn++;
  3212.    if (threshold>0) { k=threshold; jump MMbyPN; }
  3213.  
  3214.    if (threshold==0 || Refers(obj,wn-1)==0)
  3215.    {   .NoWordsMatch;
  3216.        if (indef_mode~=0)
  3217.        {   k=0; parser_action=NULL; jump MMbyPN;
  3218.        }
  3219.        rfalse;
  3220.    }
  3221.  
  3222.    if (threshold<0)
  3223.    {   threshold=1;
  3224.        dict_flags_of_noun = (w->#dict_par1) & $$01110100;
  3225.        w = NextWord();
  3226.        while (Refers(obj, wn-1))
  3227.        {   threshold++;
  3228.            if (w)
  3229.                dict_flags_of_noun = dict_flags_of_noun
  3230.                                     | ((w->#dict_par1) & $$01110100);
  3231.            w = NextWord();
  3232.        }
  3233.    }
  3234.  
  3235.    k = threshold; jump MMbyPN;
  3236. ];
  3237.  
  3238. ! ----------------------------------------------------------------------------
  3239. !  Refers works out whether the word at number wnum can refer to the object
  3240. !  obj, returning true or false.  The standard method is to see if the
  3241. !  word is listed under "name" for the object, but this is more complex
  3242. !  in languages other than English.
  3243. ! ----------------------------------------------------------------------------
  3244.  
  3245. [ Refers obj wnum   wd k l m;
  3246.     if (obj==0) rfalse;
  3247.  
  3248.     #ifdef LanguageRefers;
  3249.     k = LanguageRefers(obj,wnum); if (k>=0) return k;
  3250.     #endif;
  3251.  
  3252.     k = wn; wn = wnum; wd = NextWordStopped(); wn = k;
  3253.  
  3254.     if (parser_inflection >= 256)
  3255.     {   k = indirect(parser_inflection, obj, wd);
  3256.         if (k>=0) return k;
  3257.         m = -k;
  3258.     } else m = parser_inflection;
  3259.     k=obj.&m; l=(obj.#m)/2-1;
  3260.     for (m=0:m<=l:m++)
  3261.         if (wd==k-->m) rtrue;
  3262.     rfalse;
  3263. ];
  3264.  
  3265. [ WordInProperty wd obj prop k l m;
  3266.     k=obj.∝ l=(obj.#prop)/2-1;
  3267.     for (m=0:m<=l:m++)
  3268.         if (wd==k-->m) rtrue;
  3269.     rfalse;
  3270. ];
  3271.  
  3272. [ DictionaryLookup b l i;
  3273.   for (i=0:i<l:i++) buffer2->(2+i) = b->i;
  3274.   buffer2->1 = l;
  3275.   @tokenise buffer2 parse2;
  3276.   return parse2-->1;
  3277. ];
  3278.  
  3279. ! ----------------------------------------------------------------------------
  3280. !  NounWord (which takes no arguments) returns:
  3281. !
  3282. !   0  if the next word is unrecognised or does not carry the "noun" bit in
  3283. !      its dictionary entry,
  3284. !   1  if a word meaning "me",
  3285. !   the index in the pronoun table (plus 2) of the value field of a pronoun,
  3286. !      if the word is a pronoun,
  3287. !   the address in the dictionary if it is a recognised noun.
  3288. !
  3289. !  The "current word" marker moves on one.
  3290. ! ----------------------------------------------------------------------------
  3291.  
  3292. [ NounWord i j s;
  3293.    i=NextWord();
  3294.    if (i==0) rfalse;
  3295.    if (i==ME1__WD or ME2__WD or ME3__WD) return 1;
  3296.    s = LanguagePronouns-->0;
  3297.    for (j=1 : j<=s : j=j+3)
  3298.        if (i == LanguagePronouns-->j)
  3299.            return j+2;
  3300.    if ((i->#dict_par1)&128 == 0) rfalse;
  3301.    return i;
  3302. ];
  3303.  
  3304. ! ----------------------------------------------------------------------------
  3305. !  NextWord (which takes no arguments) returns:
  3306. !
  3307. !  0            if the next word is unrecognised,
  3308. !  comma_word   if it is a comma character
  3309. !               (which is treated oddly by the Z-machine, hence the code)
  3310. !  or the dictionary address if it is recognised.
  3311. !  The "current word" marker is moved on.
  3312. !
  3313. !  NextWordStopped does the same, but returns -1 when input has run out
  3314. ! ----------------------------------------------------------------------------
  3315.  
  3316. [ NextWord i j k;
  3317.    if (wn > parse->1) { wn++; rfalse; }
  3318.    i=wn*2-1; wn++;
  3319.    j=parse-->i;
  3320.    if (j==0)
  3321.    {   k=wn*4-3; i=buffer->(parse->k);
  3322.        if (i==',') j=comma_word;
  3323.        if (i=='.') j=THEN1__WD;
  3324.    }
  3325.    return j;
  3326. ];   
  3327.  
  3328. [ NextWordStopped;
  3329.    if (wn > parse->1) { wn++; return -1; }
  3330.    return NextWord();
  3331. ];
  3332.  
  3333. [ WordAddress wordnum;
  3334.    return buffer + parse->(wordnum*4+1);
  3335. ];
  3336.  
  3337. [ WordLength wordnum;
  3338.    return parse->(wordnum*4);
  3339. ];
  3340.  
  3341. ! ----------------------------------------------------------------------------
  3342. !  TryNumber is the only routine which really does any character-level
  3343. !  parsing, since that's normally left to the Z-machine.
  3344. !  It takes word number "wordnum" and tries to parse it as an (unsigned)
  3345. !  decimal number, returning
  3346. !
  3347. !  -1000                if it is not a number
  3348. !  the number           if it has between 1 and 4 digits
  3349. !  10000                if it has 5 or more digits.
  3350. !
  3351. !  (The danger of allowing 5 digits is that Z-machine integers are only
  3352. !  16 bits long, and anyway this isn't meant to be perfect.)
  3353. !
  3354. !  Using NumberWord, it also catches "one" up to "twenty".
  3355. !
  3356. !  Note that a game can provide a ParseNumber routine which takes priority,
  3357. !  to enable parsing of odder numbers ("x45y12", say).
  3358. ! ----------------------------------------------------------------------------
  3359.  
  3360. [ TryNumber wordnum   i j c num len mul tot d digit;
  3361.  
  3362.    i=wn; wn=wordnum; j=NextWord(); wn=i;
  3363.    j=NumberWord(j); if (j>=1) return j;
  3364.  
  3365.    i=wordnum*4+1; j=parse->i; num=j+buffer; len=parse->(i-1);
  3366.  
  3367.    tot=ParseNumber(num, len);  if (tot~=0) return tot;
  3368.  
  3369.    if (len>=4) mul=1000;
  3370.    if (len==3) mul=100;
  3371.    if (len==2) mul=10;
  3372.    if (len==1) mul=1;
  3373.  
  3374.    tot=0; c=0; len=len-1;
  3375.  
  3376.    for (c=0:c<=len:c++)
  3377.    {   digit=num->c;
  3378.        if (digit=='0') { d=0; jump digok; }
  3379.        if (digit=='1') { d=1; jump digok; }
  3380.        if (digit=='2') { d=2; jump digok; }
  3381.        if (digit=='3') { d=3; jump digok; }
  3382.        if (digit=='4') { d=4; jump digok; }
  3383.        if (digit=='5') { d=5; jump digok; }
  3384.        if (digit=='6') { d=6; jump digok; }
  3385.        if (digit=='7') { d=7; jump digok; }
  3386.        if (digit=='8') { d=8; jump digok; }
  3387.        if (digit=='9') { d=9; jump digok; }
  3388.        return -1000;
  3389.      .digok;
  3390.        tot=tot+mul*d; mul=mul/10;
  3391.    }
  3392.    if (len>3) tot=10000;
  3393.    return tot;
  3394. ];
  3395.  
  3396. ! ----------------------------------------------------------------------------
  3397. !  GetGender returns 0 if the given animate object is female, and 1 if male
  3398. !  (not all games will want such a simple decision function!)
  3399. ! ----------------------------------------------------------------------------
  3400.  
  3401. [ GetGender person;
  3402.    if (person hasnt female) rtrue;
  3403.    rfalse;
  3404. ];
  3405.  
  3406. [ GetGNAOfObject obj case gender;
  3407.    if (obj hasnt animate) case = 6;
  3408.    if (obj has male) gender = male;
  3409.    if (obj has female) gender = female;
  3410.    if (obj has neuter) gender = neuter;
  3411.    if (gender == 0)
  3412.    {   if (case == 0) gender = LanguageAnimateGender;
  3413.        else gender = LanguageInanimateGender;
  3414.    }
  3415.    if (gender == female) case = case + 1;
  3416.    if (gender == neuter) case = case + 2;
  3417.    if (obj has pluralname) case = case + 3;
  3418.    return case;
  3419. ];
  3420.  
  3421. ! ----------------------------------------------------------------------------
  3422. !  Converting between dictionary addresses and entry numbers
  3423. ! ----------------------------------------------------------------------------
  3424.  
  3425. [ Dword__No w; return (w-(0-->4 + 7))/9; ];
  3426. [ No__Dword n; return 0-->4 + 7 + 9*n; ];
  3427.  
  3428. ! ----------------------------------------------------------------------------
  3429. !  For copying buffers
  3430. ! ----------------------------------------------------------------------------
  3431.  
  3432. [ CopyBuffer bto bfrom i size;
  3433.    size=bto->0;
  3434.    for (i=1:i<=size:i++) bto->i=bfrom->i;
  3435. ];
  3436.  
  3437. ! ----------------------------------------------------------------------------
  3438. !  Provided for use by language definition files
  3439. ! ----------------------------------------------------------------------------
  3440.  
  3441. [ LTI_Insert i ch  y;
  3442.  
  3443.   !   Insert character ch into buffer at point i.
  3444.  
  3445.   !   Being careful not to let the buffer possibly overflow:
  3446.  
  3447.       y = buffer->1;
  3448.       if (y > buffer->0) y = buffer->0;
  3449.  
  3450.   !   Move the subsequent text along one character:
  3451.  
  3452.       for (y=y+2: y>i : y--) buffer->y = buffer->(y-1);
  3453.  
  3454.       buffer->i = ch;
  3455.  
  3456.   !   And the text is now one character longer:
  3457.       if (buffer->1 < buffer->0)
  3458.           (buffer->1)++;
  3459. ];
  3460.  
  3461. ! ============================================================================
  3462.  
  3463. [ PronounsSub x y c d;
  3464.  
  3465.   L__M(##Pronouns, 1);
  3466.  
  3467.   c = (LanguagePronouns-->0)/3;
  3468.   if (player ~= selfobj) c++;
  3469.  
  3470.   if (c==0) return L__M(##Pronouns, 4);
  3471.  
  3472.   for (x = 1, d = 0 : x <= LanguagePronouns-->0: x = x+3)
  3473.   {   print "~", (address) LanguagePronouns-->x, "~ ";
  3474.       y = LanguagePronouns-->(x+2);
  3475.       if (y == NULL) L__M(##Pronouns, 3);
  3476.       else { L__M(##Pronouns, 2); print (the) y; }
  3477.       d++;
  3478.       if (d < c-1) print ", ";
  3479.       if (d == c-1) print (string) AND__TX;
  3480.   }
  3481.   if (player ~= selfobj)
  3482.   {   print "~", (address) ME1__WD, "~ "; L__M(##Pronouns, 2);
  3483.       c = player; player = selfobj;
  3484.       print (the) c; player = c;
  3485.   }
  3486.   ".";
  3487. ];
  3488.  
  3489. [ SetPronoun dword value x;
  3490.   for (x = 1 : x <= LanguagePronouns-->0: x = x+3)
  3491.       if (LanguagePronouns-->x == dword)
  3492.       {   LanguagePronouns-->(x+2) = value; return;
  3493.       }
  3494.   RunTimeError(14);
  3495. ];
  3496.  
  3497. [ PronounValue dword x;
  3498.   for (x = 1 : x <= LanguagePronouns-->0: x = x+3)
  3499.       if (LanguagePronouns-->x == dword)
  3500.           return LanguagePronouns-->(x+2);
  3501.   return 0;
  3502. ];
  3503.  
  3504. [ ResetVagueWords obj; PronounNotice(obj); ];
  3505.  
  3506. #ifdef EnglishNaturalLanguage;
  3507. [ PronounOldEnglish;
  3508.    if (itobj ~= old_itobj)   SetPronoun('it', itobj);
  3509.    if (himobj ~= old_himobj) SetPronoun('him', himobj);
  3510.    if (herobj ~= old_herobj) SetPronoun('her', herobj);
  3511.    old_itobj = itobj; old_himobj = himobj; old_herobj = herobj;
  3512. ];
  3513. #endif;
  3514.  
  3515. [ PronounNotice obj x bm;
  3516.  
  3517.    if (obj == player) return;
  3518.  
  3519.    #ifdef EnglishNaturalLanguage;
  3520.    PronounOldEnglish();
  3521.    #endif;
  3522.  
  3523.    bm = PowersOfTwo_TB-->(GetGNAOfObject(obj));
  3524.  
  3525.    for (x = 1 : x <= LanguagePronouns-->0: x = x+3)
  3526.        if (bm & (LanguagePronouns-->(x+1)) ~= 0)
  3527.            LanguagePronouns-->(x+2) = obj;
  3528.  
  3529.    #ifdef EnglishNaturalLanguage;
  3530.    itobj  = PronounValue('it');  old_itobj  = itobj;
  3531.    himobj = PronounValue('him'); old_himobj = himobj;
  3532.    herobj = PronounValue('her'); old_herobj = herobj;
  3533.    #endif;
  3534. ];
  3535.  
  3536. ! ============================================================================
  3537. !  End of the parser proper: the remaining routines are its front end.
  3538. ! ----------------------------------------------------------------------------
  3539.  
  3540. Object InformLibrary "(Inform Library)"
  3541.   with play
  3542.        [ i j k l;
  3543.        standard_interpreter = $32-->0;
  3544.     
  3545.        ChangeDefault(cant_go, CANTGO__TX);
  3546.        
  3547.        real_location = thedark;
  3548.        player = selfobj;
  3549.     
  3550.        top_object = #largest_object-255;
  3551.        selfobj.capacity = MAX_CARRIED;
  3552.        #ifdef LanguageInitialise;
  3553.        LanguageInitialise();
  3554.        #endif;
  3555.        j=Initialise();
  3556.        last_score = score;
  3557.        move player to location;
  3558.        while (parent(location)~=0) location=parent(location);
  3559.        objectloop (i in player) give i moved ~concealed;
  3560.     
  3561.        if (j~=2) Banner();
  3562.  
  3563.        MoveFloatingObjects();
  3564.        lightflag=OffersLight(parent(player));
  3565.        if (lightflag==0) { real_location=location; location=thedark; }
  3566.        <Look>;
  3567.     
  3568.        for (i=1:i<=100:i++) j=random(i);
  3569.  
  3570.        #ifdef EnglishNaturalLanguage;
  3571.        old_itobj = itobj; old_himobj = himobj; old_herobj = herobj;
  3572.        #endif;
  3573.     
  3574.        while (~~deadflag)
  3575.        {   if (score ~= last_score)
  3576.            {   if (notify_mode==1) NotifyTheScore(); last_score=score; }
  3577.  
  3578.            #ifdef EnglishNaturalLanguage;
  3579.                PronounOldEnglish();
  3580.                old_itobj = PronounValue('it');
  3581.                old_himobj = PronounValue('him');
  3582.                old_herobj = PronounValue('her');
  3583.            #endif;
  3584.  
  3585.           .late__error;
  3586.  
  3587.            inputobjs-->0 = 0; inputobjs-->1 = 0;
  3588.            inputobjs-->2 = 0; inputobjs-->3 = 0; meta=false;
  3589.     
  3590.            !  The Parser writes its results into inputobjs and meta,
  3591.            !  a flag indicating a "meta-verb".  This can only be set for
  3592.            !  commands by the player, not for orders to others.
  3593.     
  3594.            InformParser.parse_input(inputobjs);
  3595.     
  3596.            action=inputobjs-->0;
  3597.  
  3598.            !  --------------------------------------------------------------
  3599.  
  3600.            !  Reverse "give fred biscuit" into "give biscuit to fred"
  3601.     
  3602.            if (action==##GiveR or ##ShowR)
  3603.            {   i=inputobjs-->2; inputobjs-->2=inputobjs-->3; inputobjs-->3=i;
  3604.                if (action==##GiveR) action=##Give; else action=##Show;
  3605.            }
  3606.     
  3607.            !  Convert "P, tell me about X" to "ask P about X"
  3608.     
  3609.            if (action==##Tell && inputobjs-->2==player && actor~=player)
  3610.            {   inputobjs-->2=actor; actor=player; action=##Ask;
  3611.            }
  3612.     
  3613.            !  Convert "ask P for X" to "P, give X to me"
  3614.     
  3615.            if (action==##AskFor && inputobjs-->2~=player && actor==player)
  3616.            {   actor=inputobjs-->2; inputobjs-->2=inputobjs-->3;
  3617.                inputobjs-->3=player; action=##Give;
  3618.            }
  3619.     
  3620.            !  For old, obsolete code: special_word contains the topic word
  3621.            !  in conversation
  3622.     
  3623.            if (action==##Ask or ##Tell or ##Answer)
  3624.                special_word = special_number1;
  3625.  
  3626.            !  --------------------------------------------------------------
  3627.     
  3628.            multiflag=false; onotheld_mode=notheld_mode; notheld_mode=false;
  3629.            !  For implicit taking and multiple object detection
  3630.     
  3631.           .begin__action;
  3632.            inp1 = 0; inp2 = 0; i=inputobjs-->1;
  3633.            if (i>=1) inp1=inputobjs-->2;
  3634.            if (i>=2) inp2=inputobjs-->3;
  3635.     
  3636.            !  inp1 and inp2 hold: object numbers, or 0 for "multiple object",
  3637.            !  or 1 for "a number or dictionary address"
  3638.     
  3639.            if (inp1 == 1) noun = special_number1; else noun = inp1;
  3640.            if (inp2 == 1)
  3641.            {   if (inp1 == 1) second = special_number2;
  3642.                else second = special_number1;
  3643.            } else second = inp2;
  3644.  
  3645.            !  --------------------------------------------------------------
  3646.     
  3647.            if (actor~=player)
  3648.            {   
  3649.            !  The player's "orders" property can refuse to allow conversation
  3650.            !  here, by returning true.  If not, the order is sent to the
  3651.            !  other person's "orders" property.  If that also returns false,
  3652.            !  then: if it was a misunderstood command anyway, it is converted
  3653.            !  to an Answer action (thus "floyd, grrr" ends up as
  3654.            !  "say grrr to floyd").  If it was a good command, it is finally
  3655.            !  offered to the Order: part of the other person's "life"
  3656.            !  property, the old-fashioned way of dealing with conversation.
  3657.     
  3658.                j=RunRoutines(player,orders);
  3659.                if (j==0)
  3660.                {   j=RunRoutines(actor,orders);
  3661.                    if (j==0)
  3662.                    {   if (action==##NotUnderstood)
  3663.                        {   inputobjs-->3=actor; actor=player; action=##Answer;
  3664.                            jump begin__action;
  3665.                        }
  3666.                        if (RunLife(actor,##Order)==0) L__M(##Order,1,actor);
  3667.                    }
  3668.                }
  3669.                jump turn__end;
  3670.            }
  3671.  
  3672.            !  --------------------------------------------------------------
  3673.            !  Generate the action...
  3674.  
  3675.            if ((i==0)
  3676.                || (i==1 && inp1 ~= 0)
  3677.                || (i==2 && inp1 ~= 0 && inp2 ~= 0))
  3678.            {   self.begin_action(action, noun, second, 0);
  3679.                jump turn__end;
  3680.            }
  3681.  
  3682.            !  ...unless a multiple object must be substituted.  First:
  3683.            !  (a) check the multiple list isn't empty;
  3684.            !  (b) warn the player if it has been cut short because too long;
  3685.            !  (c) generate a sequence of actions from the list
  3686.            !      (stopping in the event of death or movement away).
  3687.  
  3688.            multiflag = true;
  3689.            j=multiple_object-->0;
  3690.            if (j==0) { L__M(##Miscellany,2); jump late__error; }
  3691.            if (toomany_flag)
  3692.            {   toomany_flag = false; L__M(##Miscellany,1); }
  3693.            i=location;
  3694.            for (k=1:k<=j:k++)
  3695.            {   if (deadflag) break;
  3696.                if (location ~= i)
  3697.                {   L__M(##Miscellany, 51);
  3698.                    break;
  3699.                }
  3700.                l = multiple_object-->k;
  3701.                PronounNotice(l);
  3702.                print (name) l, ": ";
  3703.                if (inp1 == 0)
  3704.                {   inp1 = l; self.begin_action(action, l, second, 0); inp1 = 0;
  3705.                }
  3706.                else
  3707.                {   inp2 = l; self.begin_action(action, noun, l, 0); inp2 = 0;
  3708.                }
  3709.            }
  3710.  
  3711.            !  --------------------------------------------------------------
  3712.     
  3713.            .turn__end;
  3714.     
  3715.            !  No time passes if either (i) the verb was meta, or
  3716.            !  (ii) we've only had the implicit take before the "real"
  3717.            !  action to follow.
  3718.     
  3719.            if (notheld_mode==1) { NoteObjectAcquisitions(); continue; }
  3720.            if (meta) continue;
  3721.            if (~~deadflag) self.end_turn_sequence();
  3722.        }
  3723.  
  3724.            if (deadflag~=2) AfterLife();
  3725.            if (deadflag==0) jump late__error;
  3726.     
  3727.            print "^^    ";
  3728.            #IFV5; style bold; #ENDIF;
  3729.            print "***";
  3730.            if (deadflag==1) L__M(##Miscellany,3);
  3731.            if (deadflag==2) L__M(##Miscellany,4);
  3732.            if (deadflag>2)  { print " "; DeathMessage(); print " "; }
  3733.            print "***";
  3734.            #IFV5; style roman; #ENDIF;
  3735.            print "^^^";
  3736.            ScoreSub();
  3737.            DisplayStatus();
  3738.     
  3739.            .RRQPL;
  3740.            L__M(##Miscellany,5);
  3741.            .RRQL;
  3742.            print "> ";
  3743.            #IFV3; read buffer parse; #ENDIF;
  3744.            temp_global=0;
  3745.            #IFV5; read buffer parse DrawStatusLine; #ENDIF;
  3746.            i=parse-->1;
  3747.            if (i==QUIT1__WD or QUIT2__WD) quit;
  3748.            if (i==RESTART__WD)      @restart;
  3749.            if (i==RESTORE__WD)      { RestoreSub(); jump RRQPL; }
  3750.            if (i==FULLSCORE1__WD or FULLSCORE2__WD && TASKS_PROVIDED==0)
  3751.            {   new_line; FullScoreSub(); jump RRQPL; }
  3752.            if (deadflag==2 && i==AMUSING__WD && AMUSING_PROVIDED==0)
  3753.            {   new_line; Amusing(); jump RRQPL; }
  3754.            #IFV5;
  3755.            if (i==UNDO1__WD or UNDO2__WD or UNDO3__WD)
  3756.            {   if (undo_flag==0)
  3757.                {   L__M(##Miscellany,6);
  3758.                    jump RRQPL;
  3759.                }
  3760.                if (undo_flag==1) jump UndoFailed2;
  3761.                @restore_undo i;
  3762.                if (i==0)
  3763.                {   .UndoFailed2; L__M(##Miscellany,7);
  3764.                }
  3765.                jump RRQPL;
  3766.            }
  3767.            #ENDIF;
  3768.            L__M(##Miscellany,8);
  3769.            jump RRQL;
  3770.        ],
  3771.  
  3772.        end_turn_sequence
  3773.        [ i j;
  3774.  
  3775.            turns++;
  3776.            if (the_time~=NULL)
  3777.            {   if (time_rate>=0) the_time=the_time+time_rate;
  3778.                else
  3779.                {   time_step--;
  3780.                    if (time_step==0)
  3781.                    {   the_time++;
  3782.                        time_step = -time_rate;
  3783.                    }
  3784.                }
  3785.                the_time=the_time % 1440;
  3786.            }
  3787.  
  3788.            #IFDEF DEBUG;
  3789.            if (debug_flag & 4 ~= 0)
  3790.            {   for (i=0: i<active_timers: i++)
  3791.                {   j=the_timers-->i;
  3792.                    if (j~=0)
  3793.                    {   print (name) (j&$7fff), ": ";
  3794.                        if (j & $8000) print "daemon";
  3795.                        else
  3796.                        {   print "timer with ",
  3797.                                  j.time_left, " turns to go"; }
  3798.                        new_line;
  3799.                    }
  3800.                }
  3801.            }
  3802.            #ENDIF;
  3803.  
  3804.            for (i=0: i<active_timers: i++)
  3805.            {   if (deadflag) return;
  3806.                j=the_timers-->i;
  3807.                if (j~=0)
  3808.                {   if (j & $8000) RunRoutines(j&$7fff,daemon);
  3809.                    else
  3810.                    {   if (j.time_left==0)
  3811.                        {   StopTimer(j);
  3812.                            RunRoutines(j,time_out);
  3813.                        }
  3814.                        else
  3815.                            j.time_left=j.time_left-1;
  3816.                    }
  3817.                }
  3818.            }
  3819.            if (deadflag) return;
  3820.  
  3821.            scope_reason=EACH_TURN_REASON; verb_word=0;
  3822.            DoScopeAction(location);
  3823.            SearchScope(ScopeCeiling(player), player, 0);
  3824.            scope_reason=PARSING_REASON;
  3825.  
  3826.            if (deadflag) return;
  3827.  
  3828.            TimePasses();
  3829.  
  3830.            if (deadflag) return;
  3831.  
  3832.            AdjustLight();
  3833.  
  3834.            if (deadflag) return;
  3835.  
  3836.            NoteObjectAcquisitions();
  3837.        ],
  3838.  
  3839.        begin_action
  3840.        [ a n s source   sa sn ss r;
  3841.            sa = action; sn = noun; ss = second;
  3842.            action = a; noun = n; second = s;
  3843.            #IFDEF DEBUG;
  3844.            if (debug_flag & 2 ~= 0) TraceAction(source);
  3845.            #IFNOT;
  3846.            source = 0;
  3847.            #ENDIF;
  3848.            #IFTRUE Grammar__Version == 1;
  3849.            if ((meta || BeforeRoutines()==false) && action<256)
  3850.            {   indirect(#actions_table-->action); r = false;
  3851.            }
  3852.            else r = true;
  3853.            #IFNOT;
  3854.            if ((meta || BeforeRoutines()==false) && action<4096)
  3855.            {   indirect(#actions_table-->action); r = false;
  3856.            }
  3857.            else r = true;
  3858.            #ENDIF;
  3859.            action = sa; noun = sn; second = ss;
  3860.        ],
  3861.   has  proper;
  3862.        
  3863. [ R_Process a i j s1 s2;
  3864.    s1 = inp1; s2 = inp2;
  3865.    inp1 = i; inp2 = j; InformLibrary.begin_action(a, i, j, 1);
  3866.    inp1 = s1; inp2 = s2;
  3867. ];
  3868.  
  3869. [ NoteObjectAcquisitions i;
  3870.   objectloop (i in player && i hasnt moved)
  3871.   {   give i moved;
  3872.       if (i has scored)
  3873.       {   score = score + OBJECT_SCORE;
  3874.           things_score = things_score + OBJECT_SCORE;
  3875.       }
  3876.   }
  3877. ];
  3878.  
  3879. ! ----------------------------------------------------------------------------
  3880.  
  3881. [ TestScope obj act a al sr x y;
  3882.   x=parser_one; y=parser_two;
  3883.   parser_one=obj; parser_two=0; a=actor; al=actors_location;
  3884.   sr=scope_reason; scope_reason=TESTSCOPE_REASON;
  3885.   if (act==0) actor=player; else actor=act;
  3886.   actors_location=ScopeCeiling(actor);
  3887.   SearchScope(actors_location,actor,0); scope_reason=sr; actor=a;
  3888.   actors_location=al; parser_one=x; x=parser_two; parser_two=y;
  3889.   return x;
  3890. ];
  3891.  
  3892. [ LoopOverScope routine act x y a al;
  3893.   x = parser_one; y=scope_reason; a=actor; al=actors_location;
  3894.   parser_one=routine; if (act==0) actor=player; else actor=act;
  3895.   actors_location=ScopeCeiling(actor);
  3896.   scope_reason=LOOPOVERSCOPE_REASON;
  3897.   SearchScope(actors_location,actor,0);
  3898.   parser_one=x; scope_reason=y; actor=a; actors_location=al;
  3899. ];
  3900.  
  3901. [ BeforeRoutines;
  3902.   if (GamePreRoutine()~=0) rtrue;
  3903.   if (RunRoutines(player,orders)~=0) rtrue;
  3904.   if (location~=0 && RunRoutines(location,before)~=0) rtrue;
  3905.   scope_reason=REACT_BEFORE_REASON; parser_one=0;
  3906.   SearchScope(ScopeCeiling(player),player,0); scope_reason=PARSING_REASON;
  3907.   if (parser_one~=0) rtrue;
  3908.   if (inp1>1 && RunRoutines(inp1,before)~=0) rtrue;
  3909.   rfalse;
  3910. ];
  3911.  
  3912. [ AfterRoutines;
  3913.   scope_reason=REACT_AFTER_REASON; parser_one=0;
  3914.   SearchScope(ScopeCeiling(player),player,0); scope_reason=PARSING_REASON;
  3915.   if (parser_one~=0) rtrue;
  3916.   if (location~=0 && RunRoutines(location,after)~=0) rtrue;
  3917.   if (inp1>1 && RunRoutines(inp1,after)~=0) rtrue;
  3918.   return GamePostRoutine();
  3919. ];
  3920.  
  3921. [ RunLife a j;
  3922. #IFDEF DEBUG;
  3923.    if (debug_flag & 2 ~= 0) TraceAction(2, j);
  3924. #ENDIF;
  3925.    reason_code = j; return RunRoutines(a,life);
  3926. ];
  3927.  
  3928. [ ZRegion addr;
  3929.   switch(metaclass(addr))       ! Left over from Inform 5
  3930.   {   nothing: return 0;
  3931.       Object, Class: return 1;
  3932.       Routine: return 2;
  3933.       String: return 3;
  3934.   }
  3935. ];
  3936.  
  3937. [ PrintOrRun obj prop flag;
  3938.   if (obj.#prop > 2) return RunRoutines(obj,prop);
  3939.   if (obj.prop==NULL) rfalse;
  3940.   switch(metaclass(obj.prop))
  3941.   {   Class, Object, nothing: return RunTimeError(2,obj,prop);
  3942.       String: print (string) obj.prop; if (flag==0) new_line; rtrue;
  3943.       Routine: return RunRoutines(obj,prop);
  3944.   }
  3945. ];
  3946.  
  3947. [ ValueOrRun obj prop;
  3948.   if (obj.prop < 256) return obj.prop;
  3949.   return RunRoutines(obj, prop);
  3950. ];
  3951.  
  3952. [ RunRoutines obj prop;
  3953.    if (obj == thedark
  3954.        && prop ~= initial or short_name or description) obj=real_location;
  3955.    if (obj.&prop == 0) rfalse;
  3956.    return obj.prop();
  3957. ];
  3958.  
  3959. [ ChangeDefault prop val;
  3960.    (0-->5)-->(prop-1) = val;
  3961. ];
  3962.  
  3963. ! ----------------------------------------------------------------------------
  3964.  
  3965. [ StartTimer obj timer i;
  3966.    for (i=0:i<active_timers:i++)
  3967.        if (the_timers-->i==obj) rfalse;
  3968.    for (i=0:i<active_timers:i++)
  3969.        if (the_timers-->i==0) jump FoundTSlot;
  3970.    i=active_timers++;
  3971.    if (i*2>=MAX_TIMERS) RunTimeError(4);
  3972.    .FoundTSlot;
  3973.    if (obj.&time_left==0) RunTimeError(5,obj);
  3974.    the_timers-->i=obj; obj.time_left=timer;
  3975. ];
  3976.  
  3977. [ StopTimer obj i;
  3978.    for (i=0:i<active_timers:i++)
  3979.        if (the_timers-->i==obj) jump FoundTSlot2;
  3980.    rfalse;
  3981.    .FoundTSlot2;
  3982.    if (obj.&time_left==0) RunTimeError(5,obj);
  3983.    the_timers-->i=0; obj.time_left=0;
  3984. ];
  3985.  
  3986. [ StartDaemon obj i;
  3987.    for (i=0:i<active_timers:i++)
  3988.        if (the_timers-->i == $8000 + obj)
  3989.            rfalse;
  3990.    for (i=0:i<active_timers:i++)
  3991.        if (the_timers-->i==0) jump FoundTSlot3;
  3992.    i=active_timers++;
  3993.    if (i*2>=MAX_TIMERS) RunTimeError(4);
  3994.    .FoundTSlot3;
  3995.    the_timers-->i = $8000 + obj;
  3996. ];
  3997.  
  3998. [ StopDaemon obj i;
  3999.    for (i=0:i<active_timers:i++)
  4000.        if (the_timers-->i == $8000 + obj) jump FoundTSlot4;
  4001.    rfalse;
  4002.    .FoundTSlot4;
  4003.    the_timers-->i=0;
  4004. ];
  4005.  
  4006. ! ----------------------------------------------------------------------------
  4007.  
  4008. [ DisplayStatus;
  4009.    if (the_time==NULL)
  4010.    {   sline1=score; sline2=turns; }
  4011.    else
  4012.    {   sline1=the_time/60; sline2=the_time%60; }
  4013. ];
  4014.  
  4015. [ SetTime t s;
  4016.    the_time=t; time_rate=s; time_step=0;
  4017.    if (s<0) time_step=0-s;
  4018. ];
  4019.  
  4020. [ NotifyTheScore;
  4021.    print "^[";  L__M(##Miscellany, 50, score-last_score);  print ".]^";
  4022. ];
  4023.  
  4024. ! ----------------------------------------------------------------------------
  4025.  
  4026. [ AdjustLight flag i;
  4027.    i=lightflag;
  4028.    lightflag=OffersLight(parent(player));
  4029.  
  4030.    if (i==0 && lightflag==1)
  4031.    {   location=real_location; if (flag==0) <Look>;
  4032.    }
  4033.  
  4034.    if (i==1 && lightflag==0)
  4035.    {   real_location=location; location=thedark;
  4036.        if (flag==0) { NoteArrival();
  4037.                       return L__M(##Miscellany, 9); }
  4038.    }
  4039.    if (i==0 && lightflag==0) location=thedark;
  4040. ];
  4041.  
  4042. [ OffersLight i j;
  4043.    if (i==0) rfalse;
  4044.    if (i has light) rtrue;
  4045.    objectloop (j in i)
  4046.        if (HasLightSource(j)==1) rtrue;
  4047.    if (i has container)
  4048.    {   if (i has open || i has transparent)
  4049.            return OffersLight(parent(i));
  4050.    }
  4051.    else
  4052.    {   if (i has enterable || i has transparent || i has supporter)
  4053.            return OffersLight(parent(i));
  4054.    }
  4055.    rfalse;
  4056. ];
  4057.  
  4058. [ HasLightSource i j ad;
  4059.    if (i==0) rfalse;
  4060.    if (i has light) rtrue;
  4061.    if (i has enterable || IsSeeThrough(i)==1)
  4062.    {   objectloop (i in i)
  4063.            if (HasLightSource(i)==1) rtrue;
  4064.    }
  4065.    ad = i.&add_to_scope;
  4066.    if (parent(i)~=0 && ad ~= 0)
  4067.    {   if (ad-->0 > top_object)
  4068.        {   ats_hls = 0; ats_flag = 1;
  4069.            RunRoutines(i, add_to_scope);
  4070.            ats_flag = 0; if (ats_hls == 1) rtrue;
  4071.        }
  4072.        else
  4073.        {   for (j=0:(2*j)<i.#add_to_scope:j++)
  4074.                if (HasLightSource(ad-->j)==1) rtrue;
  4075.        }
  4076.    }
  4077.    rfalse;
  4078. ];
  4079.  
  4080. [ ChangePlayer obj flag i;
  4081.   if (obj.&number==0) return RunTimeError(7,obj);
  4082.   if (actor==player) actor=obj;
  4083.   give player ~transparent ~concealed;
  4084.   i=obj; while(parent(i)~=0) { if (i has animate) give i transparent;
  4085.                                i=parent(i); }
  4086.   if (player==selfobj) player.short_name=FORMER__TX;
  4087.   player.number=real_location; player=obj;
  4088.   if (player==selfobj) player.short_name=NULL;
  4089.   give player transparent concealed animate proper;
  4090.   i=player; while(parent(i)~=0) i=parent(i); location=i;
  4091.   real_location=player.number;
  4092.   if (real_location==0) real_location=location;
  4093.   lightflag=OffersLight(parent(player));
  4094.   if (lightflag==0) location=thedark;
  4095.   print_player_flag=flag;
  4096. ];
  4097.  
  4098. ! ----------------------------------------------------------------------------
  4099.  
  4100. #IFDEF DEBUG;
  4101. [ DebugParameter w x n l;
  4102.   x=0-->4; x=x+(x->0)+1; l=x->0; n=(x+1)-->0; x=w-(x+3);
  4103.   print w;
  4104.   if (w>=1 && w<=top_object) print " (", (name) w, ")";
  4105.   if (x%l==0 && (x/l)<n) print " ('", (address) w, "')";
  4106. ];
  4107. [ DebugAction a anames;
  4108. #iftrue Grammar__Version==1;
  4109.   if (a>=256) { print "<fake action ", a-256, ">"; return; }
  4110. #ifnot;
  4111.   if (a>=4096) { print "<fake action ", a-4096, ">"; return; }
  4112. #endif;
  4113.   anames = #identifiers_table;
  4114.   anames = anames + 2*(anames-->0) + 2*48;
  4115.   print (string) anames-->a;
  4116. ];
  4117. [ DebugAttribute a anames;
  4118.   if (a<0 || a>=48) print "<invalid attribute ", a, ">";
  4119.   else
  4120.   {   anames = #identifiers_table; anames = anames + 2*(anames-->0);
  4121.       print (string) anames-->a;
  4122.   }
  4123. ];
  4124. [ TraceAction source ar;
  4125.   if (source<2) print "[ Action ", (DebugAction) action;
  4126.   else
  4127.   {   if (ar==##Order)
  4128.           print "[ Order to ", (name) actor, ": ", (DebugAction) action;
  4129.       else
  4130.           print "[ Life rule ", (DebugAction) ar;
  4131.   }
  4132.   if (noun~=0)   print " with noun ", (DebugParameter) noun;
  4133.   if (second~=0) print " and second ", (DebugParameter) second;
  4134.   if (source==0) print " ";
  4135.   if (source==1) print " (from < > statement) ";
  4136.   print "]^";
  4137. ];
  4138. [ DebugToken token;
  4139.   AnalyseToken(token);
  4140.   switch(found_ttype)
  4141.   {   ILLEGAL_TT: print "<illegal token number ", token, ">";
  4142.       ELEMENTARY_TT:
  4143.       switch(found_tdata)
  4144.       {   NOUN_TOKEN:        print "noun";
  4145.           HELD_TOKEN:        print "held";
  4146.           MULTI_TOKEN:       print "multi";
  4147.           MULTIHELD_TOKEN:   print "multiheld";
  4148.           MULTIEXCEPT_TOKEN: print "multiexcept";
  4149.           MULTIINSIDE_TOKEN: print "multiinside";
  4150.           CREATURE_TOKEN:    print "creature";
  4151.           SPECIAL_TOKEN:     print "special";
  4152.           NUMBER_TOKEN:      print "number";
  4153.           TOPIC_TOKEN:       print "topic";
  4154.           ENDIT_TOKEN:       print "END";
  4155.       }
  4156.       PREPOSITION_TT:
  4157.           print "'", (address) found_tdata, "'";
  4158.       ROUTINE_FILTER_TT:
  4159.           print "noun=Routine(", found_tdata, ")";
  4160.       ATTR_FILTER_TT:
  4161.           print (DebugAttribute) found_tdata;
  4162.       SCOPE_TT:
  4163.           print "scope=Routine(", found_tdata, ")";
  4164.       GPR_TT:
  4165.           print "Routine(", found_tdata, ")";
  4166.   }
  4167. ];
  4168. [ DebugGrammarLine pcount;
  4169.   print " * ";
  4170.   for (:line_token-->pcount ~= ENDIT_TOKEN:pcount++)
  4171.   {   if ((line_token-->pcount)->0 & $10) print "/ ";
  4172.       print (DebugToken) line_token-->pcount, " ";
  4173.   }
  4174.   print "-> ", (DebugAction) action_to_be;
  4175.   if (action_reversed) print " reverse";
  4176. ];
  4177. [ ShowVerbSub address lines da meta i j;
  4178.     if (((noun->#dict_par1) & 1) == 0)
  4179.       "Try typing ~showverb~ and then the name of a verb.";
  4180.     meta=((noun->#dict_par1) & 2)/2;
  4181.     i = $ff-(noun->#dict_par2);
  4182.     address = (0-->7)-->i;
  4183.     lines = address->0;
  4184.     address++;
  4185.     print "Verb ";
  4186.     if (meta) print "meta ";
  4187.     da = 0-->4;
  4188.     for (j=0:j < (da+5)-->0:j++)
  4189.         if (da->(j*9 + 14) == $ff-i)
  4190.             print "'", (address) (da + 9*j + 7), "' ";
  4191.     new_line;
  4192.     if (lines == 0) "has no grammar lines.";
  4193.     for (:lines > 0:lines--)
  4194.     {   address = UnpackGrammarLine(address);
  4195.         print "    "; DebugGrammarLine(); new_line;
  4196.     }
  4197. ];
  4198. [ ShowobjSub c f l a n x;
  4199.    if (noun==0) noun=location;
  4200.    objectloop (c in Class) if (noun ofclass c) { f++; l=c; }
  4201.    new_line;if (f == 1) print (name) l, " ~"; else print "Object ~";
  4202.    print (name) noun, "~ (", noun, ")";
  4203.    if (parent(noun)~=0) print " in ~", (name) parent(noun), "~";
  4204.    new_line;
  4205.    if (f > 1)
  4206.    {   print "  class ";
  4207.        objectloop (c in Class) if (noun ofclass c) print (name) c, " ";
  4208.        new_line;
  4209.    }
  4210.    for (a=0,f=0:a<48:a++) if (noun has a) f=1;
  4211.    if (f)
  4212.    {   print "  has ";
  4213.        for (a=0:a<48:a++) if (noun has a) print (DebugAttribute) a, " ";
  4214.        new_line;
  4215.    }
  4216.    if (noun ofclass Class) return;
  4217.  
  4218.    f=0; l = #identifiers_table-->0;
  4219.    for (a=1:a<=l:a++)
  4220.    {   if ((a~=2 or 3) && noun.&a)
  4221.        {   if (f==0) { print "  with "; f=1; }
  4222.            print (property) a;
  4223.            n = noun.#a;
  4224.            for (c=0:2*c<n:c++)
  4225.            {   print " ";
  4226.                x = (noun.&a)-->c;
  4227.                if (a==name) print "'", (address) x, "'";
  4228.                else
  4229.                {   if (a==number or capacity or time_left)
  4230.                        print x;
  4231.                    else
  4232.                    {   switch(x)
  4233.                        {   NULL: print "NULL";
  4234.                            0: print "0";
  4235.                            1: print "1";
  4236.                            default:
  4237.                            switch(metaclass(x))
  4238.                            {   Class, Object: print (name) x;
  4239.                                String: print "~", (string) x, "~";
  4240.                                Routine: print "[...]";
  4241.                            }
  4242.                            print " (", x, ")";
  4243.                        }
  4244.                    }
  4245.                }
  4246.            }
  4247.            print ",^       ";
  4248.        }
  4249.    }
  4250.    if (f==1) new_line;
  4251. ];
  4252. #ENDIF;
  4253.  
  4254. ! ----------------------------------------------------------------------------
  4255. !  Except in Version 3, the DrawStatusLine routine does just that: this is
  4256. !  provided explicitly so that it can be Replace'd to change the style, and
  4257. !  as written it emulates the ordinary Standard game status line, which is
  4258. !  drawn in hardware
  4259. ! ----------------------------------------------------------------------------
  4260.  
  4261. #IFV5;
  4262. [ DrawStatusLine width posa posb;
  4263.    @split_window 1; @set_window 1; @set_cursor 1 1; style reverse;
  4264.    width = 0->33; posa = width-26; posb = width-13;
  4265.    spaces width;
  4266.    @set_cursor 1 2; print (name) location;
  4267.    if ((0->1)&2 == 0)
  4268.    {   if (width > 76)
  4269.        {   @set_cursor 1 posa; print (string) SCORE__TX, sline1;
  4270.            @set_cursor 1 posb; print (string) MOVES__TX, sline2;
  4271.        }
  4272.        if (width > 63 && width <= 76)
  4273.        {   @set_cursor 1 posb; print sline1, "/", sline2;
  4274.        }
  4275.    }
  4276.    else
  4277.    {   @set_cursor 1 posa;
  4278.        print (string) TIME__TX;
  4279.        LanguageTimeOfDay(sline1, sline2);
  4280.    }
  4281.    @set_cursor 1 1; style roman; @set_window 0;
  4282. ];
  4283. #ENDIF;
  4284.  
  4285. ! ----------------------------------------------------------------------------
  4286. !  Much better menus can be created using the optional library extension
  4287. !  "menus.h".  These are provided for compatibility with previous practice:
  4288. ! ----------------------------------------------------------------------------
  4289.  
  4290. [ LowKey_Menu menu_choices EntryR ChoiceR lines main_title i j;
  4291.   menu_nesting++;
  4292.  .LKRD;
  4293.   menu_item=0;
  4294.   lines=indirect(EntryR);
  4295.   main_title=item_name;
  4296.  
  4297.   print "--- "; print (string) main_title; print " ---^^";
  4298.  
  4299.   if (menu_choices ofclass Routine) menu_choices.call();
  4300.   else print (string) menu_choices;
  4301.  
  4302.   for (::)
  4303.   {   L__M(##Miscellany, 52, lines);
  4304.       print "> ";
  4305.  
  4306.       #IFV3; read buffer parse;
  4307.       #IFNOT; read buffer parse DrawStatusLine;
  4308.       #ENDIF;
  4309.  
  4310.       i=parse-->1;
  4311.       if (i==QUIT1__WD or QUIT2__WD || parse->1==0)
  4312.       {   menu_nesting--; if (menu_nesting>0) rfalse;
  4313.           if (deadflag==0) <<Look>>;
  4314.           rfalse;
  4315.       }
  4316.       i=TryNumber(1);
  4317.       if (i==0) jump LKRD;
  4318.       if (i<1 || i>lines) continue;
  4319.       menu_item=i;
  4320.       j=indirect(ChoiceR);
  4321.       if (j==2) jump LKRD;
  4322.       if (j==3) rfalse;
  4323.   }
  4324. ];
  4325.  
  4326. #IFV3;
  4327. [ DoMenu menu_choices EntryR ChoiceR;
  4328.   LowKey_Menu(menu_choices,EntryR,ChoiceR);
  4329. ];
  4330. #ENDIF;
  4331.  
  4332. #IFV5;
  4333. [ DoMenu menu_choices EntryR ChoiceR
  4334.          lines main_title main_wid cl i j oldcl pkey;
  4335.  
  4336.   if (pretty_flag==0)
  4337.       return LowKey_Menu(menu_choices,EntryR,ChoiceR);
  4338.  
  4339.   menu_nesting++;
  4340.   menu_item=0;
  4341.   lines=indirect(EntryR);
  4342.   main_title=item_name; main_wid=item_width;
  4343.   cl=7;
  4344.  
  4345.   .ReDisplay;
  4346.       oldcl=0;
  4347.       @erase_window $ffff;
  4348.       i=lines+7;
  4349.       @split_window i;
  4350.       i = 0->33;
  4351.       if (i==0) i=80;
  4352.       @set_window 1;
  4353.       @set_cursor 1 1;
  4354.       style reverse;
  4355.       spaces(i); j=i/2-main_wid;
  4356.       @set_cursor 1 j;
  4357.       print (string) main_title;
  4358.       @set_cursor 2 1; spaces(i);
  4359.       @set_cursor 2 2; print (string) NKEY__TX;
  4360.       j=i-12; @set_cursor 2 j; print (string) PKEY__TX;
  4361.       @set_cursor 3 1; spaces(i);
  4362.       @set_cursor 3 2; print (string) RKEY__TX;
  4363.       j=i-17; @set_cursor 3 j;
  4364.       if (menu_nesting==1) print (string) QKEY1__TX;
  4365.                       else print (string) QKEY2__TX;
  4366.       style roman;
  4367.       @set_cursor 5 2; font off;
  4368.  
  4369.       if (menu_choices ofclass String) print (string) menu_choices;
  4370.       else menu_choices.call();
  4371.  
  4372.       for (::)
  4373.       {   if (cl ~= oldcl)
  4374.           {   if (oldcl>0) { @set_cursor oldcl 4; print " "; }
  4375.               @set_cursor cl 4; print ">";
  4376.           }
  4377.           oldcl=cl;
  4378.           @read_char 1 -> pkey;
  4379.           if (pkey==NKEY1__KY or NKEY2__KY or 130)
  4380.           {   cl++; if (cl==7+lines) cl=7; continue;
  4381.           }
  4382.           if (pkey==PKEY1__KY or PKEY2__KY or 129)
  4383.           {   cl--; if (cl==6)  cl=6+lines; continue;
  4384.           }
  4385.           if (pkey==QKEY1__KY or QKEY2__KY or 27 or 131) break;
  4386.           if (pkey==10 or 13 or 132)
  4387.           {   @set_window 0; font on;
  4388.               new_line; new_line; new_line;
  4389.     
  4390.               menu_item=cl-6;
  4391.               EntryR.call();
  4392.     
  4393.               @erase_window $ffff;
  4394.               @split_window 1;
  4395.               i = 0->33; if (i==0) { i=80; }
  4396.               @set_window 1; @set_cursor 1 1; style reverse; spaces(i);
  4397.               j=i/2-item_width;
  4398.               @set_cursor 1 j;
  4399.               print (string) item_name;
  4400.               style roman; @set_window 0; new_line;
  4401.     
  4402.               i = ChoiceR.call();
  4403.               if (i==2) jump ReDisplay;
  4404.               if (i==3) break;
  4405.     
  4406.               L__M(##Miscellany, 53);
  4407.               @read_char 1 -> pkey; jump ReDisplay;
  4408.           }
  4409.       }
  4410.  
  4411.       menu_nesting--; if (menu_nesting>0) rfalse;
  4412.       font on; @set_cursor 1 1;
  4413.       @erase_window $ffff; @set_window 0;
  4414.       new_line; new_line; new_line;
  4415.       if (deadflag==0) <<Look>>;
  4416. ];  
  4417. #ENDIF;
  4418.  
  4419. ! ----------------------------------------------------------------------------
  4420.  
  4421. #ifv5;
  4422. Array StorageForShortName table 160;
  4423. #endif;
  4424.  
  4425. [ PrefaceByArticle o acode pluralise  i artform findout;
  4426.  
  4427.    if (o provides articles)
  4428.    {   print (string) (o.&articles)-->(acode+short_name_case*LanguageCases),
  4429.            " ";
  4430.        if (pluralise) return;
  4431.        print (PSN__) o; return;
  4432.    }
  4433.  
  4434.    i = GetGNAOfObject(o);
  4435.    if (pluralise)
  4436.    {   if (i<3 || (i>=6 && i<9)) i = i + 3;
  4437.    }
  4438.    i = LanguageGNAsToArticles-->i;
  4439.  
  4440.    artform = LanguageArticles
  4441.              + 6*LanguageContractionForms*(short_name_case + i*LanguageCases);
  4442.  
  4443. #iftrue LanguageContractionForms == 2;
  4444.    if (artform-->acode ~= artform-->(acode+3)) findout = true;
  4445. #endif;
  4446. #iftrue LanguageContractionForms == 3;
  4447.    if (artform-->acode ~= artform-->(acode+3)) findout = true;
  4448.    if (artform-->(acode+3) ~= artform-->(acode+6)) findout = true;
  4449. #endif;
  4450. #iftrue LanguageContractionForms == 4;
  4451.    if (artform-->acode ~= artform-->(acode+3)) findout = true;
  4452.    if (artform-->(acode+3) ~= artform-->(acode+6)) findout = true;
  4453.    if (artform-->(acode+6) ~= artform-->(acode+9)) findout = true;
  4454. #endif;
  4455. #iftrue LanguageContractionForms > 4;
  4456.    findout = true;
  4457. #endif;
  4458.  
  4459.    if (standard_interpreter ~= 0 && findout)
  4460.    {   StorageForShortName-->0 = 160;
  4461.        @output_stream 3 StorageForShortName;
  4462.        if (pluralise) print (number) pluralise; else print (PSN__) o;
  4463.        @output_stream -3;
  4464.        acode = acode + 3*LanguageContraction(StorageForShortName + 2);
  4465.    }
  4466.  
  4467.    print (string) artform-->acode;
  4468.    if (pluralise) return;
  4469.    print (PSN__) o;
  4470. ];
  4471.  
  4472. [ PSN__ o;
  4473.    if (o==0) { print (string) NOTHING__TX; rtrue; }
  4474.    switch(metaclass(o))
  4475.    {   Routine: print "<routine ", o, ">"; rtrue;
  4476.        String:  print "<string ~", (string) o, "~>"; rtrue;
  4477.        nothing: print "<illegal object number ", o, ">"; rtrue;
  4478.    }
  4479.    if (o==player) { print (string) YOURSELF__TX; rtrue; }
  4480.    #ifdef LanguagePrintShortName;
  4481.    if (LanguagePrintShortName(o)) rtrue;
  4482.    #endif;
  4483.    if (indef_mode && o.&short_name_indef~=0
  4484.        && PrintOrRun(o, short_name_indef, 1)~=0) rtrue;
  4485.    if (o.&short_name~=0 && PrintOrRun(o,short_name,1)~=0) rtrue;
  4486.    @print_obj o;
  4487. ];
  4488.  
  4489. [ Indefart o i;
  4490.    i = indef_mode; indef_mode = true;
  4491.    if (o has proper) { indef_mode = NULL; print (PSN__) o; return; }
  4492.    if (o provides article)
  4493.    {   PrintOrRun(o,article,1); print " ", (PSN__) o; indef_mode = i; return;
  4494.    }
  4495.    PrefaceByArticle(o, 2); indef_mode = i;
  4496. ];
  4497. [ Defart o i;
  4498.    i = indef_mode; indef_mode = false;
  4499.    if (o has proper)
  4500.    { indef_mode = NULL; print (PSN__) o; indef_mode = i; return; }
  4501.    PrefaceByArticle(o, 1); indef_mode = i;
  4502. ];
  4503. [ CDefart o i;
  4504.    i = indef_mode; indef_mode = false;
  4505.    if (o has proper)
  4506.    { indef_mode = NULL; print (PSN__) o; indef_mode = i; return; }
  4507.    PrefaceByArticle(o, 0); indef_mode = i;
  4508. ];
  4509.  
  4510. [ PrintShortName o i;
  4511.    i = indef_mode; indef_mode = NULL;
  4512.    PSN__(o); indef_mode = i;
  4513. ];
  4514.  
  4515. [ EnglishNumber n; LanguageNumber(n); ];
  4516.  
  4517. [ NumberWord o i n;
  4518.   n = LanguageNumbers-->0;
  4519.   for (i=1:i<=n:i=i+2)
  4520.       if (o == LanguageNumbers-->i)
  4521.           return LanguageNumbers-->(i+1);
  4522.   return 0;
  4523. ];
  4524.  
  4525. [ RandomEntry tab;
  4526.   if (tab-->0==0) return RunTimeError(8);
  4527.   return tab-->(random(tab-->0));
  4528. ];
  4529.  
  4530. ! ----------------------------------------------------------------------------
  4531. !  Useful routine: unsigned comparison (for addresses in Z-machine)
  4532. !    Returns 1 if x>y, 0 if x=y, -1 if x<y
  4533. ! ----------------------------------------------------------------------------
  4534.  
  4535. [ UnsignedCompare x y u v;
  4536.   if (x==y) return 0;
  4537.   if (x<0 && y>=0) return 1;
  4538.   if (x>=0 && y<0) return -1;
  4539.   u = x&$7fff; v= y&$7fff;
  4540.   if (u>v) return 1;
  4541.   return -1;
  4542. ];
  4543.  
  4544. ! ----------------------------------------------------------------------------
  4545.  
  4546. [ Banner i;
  4547.    if (Story ~= 0)
  4548.    {
  4549. #IFV5; style bold; #ENDIF;
  4550.    print (string) Story;
  4551. #IFV5; style roman; #ENDIF;
  4552.    }
  4553.    if (Headline ~= 0)
  4554.        print (string) Headline;
  4555.    print "Release ", (0-->1) & $03ff, " / Serial number ";
  4556.    for (i=18:i<24:i++) print (char) 0->i;
  4557.    print " / Inform v"; inversion;
  4558.    print " Library ", (string) LibRelease;
  4559. #ifdef DEBUG;
  4560.    print " D";
  4561. #endif;
  4562.    new_line;
  4563.    if (standard_interpreter > 0)
  4564.        print "Standard interpreter ",
  4565.            standard_interpreter/256, ".", standard_interpreter%256, "^";
  4566. ];
  4567.  
  4568. [ VersionSub;
  4569.   Banner();
  4570. #IFV5;
  4571.   print "Interpreter ", 0->$1e, " Version ", (char) 0->$1f, " / ";
  4572. #ENDIF;
  4573.   print "Library serial number ", (string) LibSerial, "^";
  4574. #IFDEF LanguageVersion;
  4575.   print (string) LanguageVersion, "^";
  4576. #ENDIF;
  4577. ];
  4578.  
  4579. [ RunTimeError n p1 p2;
  4580. #IFDEF DEBUG;
  4581.   print "** Library error ", n, " (", p1, ",", p2, ") **^** ";
  4582.   switch(n)
  4583.   {   1: print "preposition not found (this should not occur)";
  4584.       2: print "Property value not routine or string: ~",
  4585.                (property) p2, "~ of ~", (name) p1, "~ (", p1, ")";
  4586.       3: print "Entry in property list not routine or string: ~",
  4587.                (property) p2, "~ list of ~", (name) p1, "~ (", p1, ")";
  4588.       4: print "Too many timers/daemons are active simultaneously.  The
  4589.                 limit is the library constant MAX_TIMERS (currently ",
  4590.                 MAX_TIMERS, ") and should be increased";
  4591.       5: print "Object ~", (name) p1, "~ has no ~time_left~ property";
  4592.       7: print "The object ~", (name) p1, "~ can only be used as a player
  4593.                 object if it has the ~number~ property";
  4594.       8: print "Attempt to take random entry from an empty table array";
  4595.       9: print p1, " is not a valid direction property number";
  4596.       10: print "The player-object is outside the object tree";
  4597.       11: print "The room ~", (name) p1, "~ has no ~description~ property";
  4598.       12: print "Tried to set a non-existent pronoun using SetPronoun";
  4599.       13: print "A 'topic' token can only be followed by a preposition";
  4600.       default: print "(unexplained)";
  4601.   }
  4602.   " **";
  4603. #IFNOT;
  4604.   "** Library error ", n, " (", p1, ",", p2, ") **";
  4605. #ENDIF;
  4606. ];
  4607.  
  4608. ! ----------------------------------------------------------------------------
  4609.